hi passing user_id user model , joining profile table retrieve first name of user so: public function scopefirstnamebyuserid($id) { return static::where('users.id','=',$id)->join('profiles', function ($join,$id) { $join->where('profiles.user_id', '=', $id); })->pluck('firstname'); } usage: user::firstnamebyuserid(2); however following error: missing argument 2 user::{closure}() edit# the function has been updated to: public function scopefirstnamebyuserid($id) { return static::where('users.id','=',$id)->join('profiles',function ($join) use ($id) { $join->where('profiles.user_id', '=', $id); })->pluck('firstname'); } but throws error: object of class illuminate\database\eloquent\builder not converted string any ideas i'm doing wrong? in...
Comments
Post a Comment