Im very new to Laravel. I want to display the data i needed and i create a relationship to my tables but its not working. Can you find any of my mistakes?
i have two tables Users and Places
Users Model
protected $fillable = array('name', 'email', 'password','role','places_id');
public function places(){
return $this->belongsTo('App\Places');
}
Places Model
protected $fillable = array('name','email','phone','address','bio');
public function users()
{
return $this->hasMany('App\User');
}
Controller
$users = User::with('Places')->get();
return view('/dashboard')->with('users',$users);
The output is
Collection {#121 ▼
#items: array:3 [▼
0 => User {#322 ▶}
1 => User {#323 ▶}
2 => User {#324 ▼
#fillable: array:5 [▶]
#hidden: array:2 [▶]
#connection: "mysql"
#table: "users"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:10 [▶]
#original: array:10 [▶]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: array:1 [▼
"Places" => null
]
#touches: []
+timestamps: true
#visible: []
#guarded: array:1 [▶]
#rememberTokenName: "remember_token"
}
]
}
Aucun commentaire:
Enregistrer un commentaire