php - How can I display on laravel blade name instead of id? -


user can create invitations, , want display user name sended invitation , email got not working

invite.php

public function user() {     return $this->belongsto(user::class); } 

user.php

public function invites() {     return $this->hasmany(invite::class); } 

invitationcontroller.php

public function index() {     $invites = invite::all();     return view('administrar', compact('invites')); } 

administrar.blade.php

   <select class="form-control input-lg">           @foreach ($invites $invite)             <option>{{$invite->email}} invitado por {{$invite->user->name}}</option>           @endforeach      </select> 

hasmany expects user_id foreign key. (snake case)

in case, it's different need tell relationship foreign key have.

so relation should this,

public function user() {     return $this->belongsto(user::class, 'useid'); } 

or rename foreign key.

check documentation more details

eloquent: 1 many.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -