when i send a letter, i catch sender_id with auth()->user()->id
and save into the letter table
but just user_id will save, like 2 or 3 ...
how can i show user name in my view ?
list.blade.php :
<tr>
<td></td>
</tr>
LetterController.php -> public function index :
$letters = Letter::latest()->paginate(10)->where('recieve_id', '=', auth()->user()->id);
LetterController.php -> public function store :
Letter::create([
'sender_id' => auth()->user()->id,
]);
letter table :
$table->string('sender_id');
and i have a relation but i dont know it is correct or not
Letter.php :
public function user()
{
return $this->belongsTo(User::class, 'id', 'sender_id');
}
User.php:
public function letter()
{
return $this->hasMany(Letter::class);
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire