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
Comments
Post a Comment