Laravel search from two tables
<p>i want make search engine that would search by given name in partnership table clients by row "name" but cant figure out how should i make it... For now search engine works perfect but i can search only through two columns that i have described. When i try to add column name 'name' it says that variable is undefined</p>

<p>Here is my model Client.php</p>

<pre><code>&lt;?php
namespace App;
use Illuminate\Database\Eloquent\Model;

class Client extends Model {
    protected $fillable = [
        'name',
        'nip',
        'telephone',
        'email',
        'address'
    ];
    public function licenses() {
        return $this-&gt;hasMany('App\License');
    }
}
</code></pre>

<p>This is my model License.php</p>

<pre><code>&lt;?php
namespace App;
use Illuminate\Database\Eloquent\Model;

class License extends Model {
    protected $fillable = [
        'productName',
        'licenseNumber',
        'fvNumber',
        'buyDate',
        'other',
        'client_id'
    ];
    public function client() {
        return $this-&gt;belongsTo('App\Client');
    }
}
</code></pre>

<p>And my Controller</p>

<pre><code>&lt;?php
namespace App\Http\Controllers;
use Request;
use DB;
use App\Http\Requests;
use App\Http\Requests\CreateLicenseRequest;
use App\License;
use App\Client;

class LicensesController extends Controller {
    public function index() {
        $licenses = License::get();
        $search = \Request::get('search'); 
        $licenses = License::where('productName','like','%'.$search.'%')
            -&gt;orWhere('licenseNumber','like','%'.$search.'%')
            -&gt;orderBy('id')
            -&gt;paginate(20);
        return view('admin.crm.licenses.all',compact('licenses'));
    }
</code></pre>