Route::resource('posts', PostController::class);
public function __construct()
{
$this->authorizeResource(Post::class, 'post');
}
public function show(Post $post)
{
$post->load('reviews.user');
return view('post.show', compact('post'));
}
public function view(?User $user, Post $post): bool
{
if ($user && $user->can('update', $post)) {
return true;
}
return $post->is_good;
}
public function update(User $user, Post $post): bool
{
return $post->user_id === $user->id;
}
const STATUS__GOOD = 1;
public function getRouteKeyName(): string
{
return 'slug';
}
public function getIsGoodAttribute(): bool
{
return $this->status === self::STATUS__GOOD;
}