I have following two models in laravel using Eloquent:
Parent Appraisal model as below:
class Appraisal extends \Eloquent
{
protected $table = 'scope_appraisal';
protected $primaryKey = 'appraisal_id';
public function appraisalInfo()
{
return $this->hasOne('AppraisalInfo', 'appraisal_id', 'appraisal_id');
}
}
Relational AppraisalInfo model as below:
class AppraisalInfo extends \Eloquent
{
protected $table = 'scope_appraisal_info';
protected $primaryKey = 'appraisal_info_id';
public function appraisal()
{
return $this->belongsTo('V2_0\Appraisal', 'appraisal_id', 'appraisal_id');
}
public function scopeBorrowerName($query, $name)
{
return $query->where('appraisal_info_borrower', 'LIKE', '%' . trim($name) . '%');
}
}
I have make query with "LeftJoin" in controller as below:
// QUERY USING LEFT JOIN
$queryObj = Appraisal::leftJoin('scope_appraisal_info', function ($join)
{
$join->on('scope_appraisal.appraisal_id', '=', 'scope_appraisal_info.appraisal_id');
});
$queryObj = $queryObj->borrowerName('xyzname');
$result = $queryObj->get();
But, It was returning me Error as below:
Call to undefined method Illuminate\Database\Query\Builder::borrowerName()
So, How can i access scope from relational model with above query..?
Please, Let me know if anyone knows....Thanks!