Код: Выделить всё
Route::get('/', function () {
$posts = [];
if (Auth::check()) {
$posts = Auth::user()->usersCoolPosts()->latest()->get();
}
return view('home', ['posts' => $posts]);
});
Код: Выделить всё
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
public function usersCoolPosts()
{
return $this->hasMany(Post::class, 'user_id');
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... working-ru
Мобильная версия