dimanche 20 septembre 2020

Laravel strange behavior in 1 to Many relationship

Very strange situation in Laravel 1 to Many relationships, My User model

public function reminder(){

        return $this->hasMany(Reminder::class);
    }

Reminder Model

public function user(){

        return $this->belongsTo(User::class);
    }

When I try to get

dd(auth()->user()->reminder) -> null
$user_id = auth()->user()->id;
$user = User::findOrFail($user_id);
dd($user->reminder) -> success I got results.

Question is why I can't get relationship result using auth()->user()->reminder???



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire