Получается 3 модели Post, Review, Comment.
public function scopeParents($query)
{
return $query->whereNull('parent_id');
}
public function commentable():
{
return $this->morphTo();
}
public function comments()
{
return $this->morphMany('App\Models\Comment', 'commentable');
}
public function lastEpisode()
{
// или с другой сортировкой
return $this->hasOne(Series::class)->latest();
}
Serial::with('lastEpisod')
->get();
$users = User::with('posts')
->withCount('posts')
->get();
@foreach ($users as $user)
{{ $user->name }} {{ $user->posts_count }}
@foreach ($user->posts as $post)
{{ $post->title }}
@endforeach
@endforeach
$this->model = $id ? Model::findOrFail($id) : new Model();
View::share([
'messageCount' => Message::count(),
]);
User::whereHas('companies', function ($query) {
$query->where('active', true);
})->get();
Route::get('/pages/{page:slug}', 'PageController@show')->name('pages.show');
public function show(Page $page)
{
$page->increment('views');
return view('page.show', compact('page'));
}
А как делать конкретные страницы по типу site.ru/about/, не говорят.
Route::view('about', 'page.about')->name('about');
No query results for model
'user' => $this->user->name,
if(! $token = Auth::login($user)){
return response()->json(['error' => 'Unauthorized'], 401);
}
Gate::define('view-admin', function (User $user) {
return $user->is_admin;
});
Route::middleware(['web', 'can:view-admin'])
->namespace($this->namespace)
->group(base_path('routes/admin/web.php'));
@can('view-admin')
кнопка
@endcan
if ($user->can('view-admin')) {
// code
}