php - laravel retrieving profile firstname from model returns Object of class Illuminate\Database\Eloquent\Builder could not be converted to string -


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 code:

function ($join,$id) {  } 

should be:

function ($join) use ($id) {     $join->where('profiles.user_id', '=', $id); } 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -