I'm working in Laravel 5. My situation is the next: I have a table USERS and a table PROFILES the have a relation 1:1. So I have in the model users a method called profile like this:
public function profile(){
return $this->belongsTo('App\models\Profile','profile_id');
}
Also I have a method scopeData where I want to filter what users have identity_doc equal as data:
public function scopeData($query,$data){
$profile=$this->profile;
$query->where($profile->identity_doc,$data);
}
in the user controller I use the scope function in this line:
$students= Users::data($request->get('data'))->where('rol','=','Student')->get();
but, when I runned it I have this error: Trying to get property of non-object so, why it happens? the profile method works fine in others functions, but no here, I get:
**array('query' => object(Builder), 'data' => 'example', 'profile' => null))**
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire