-
app/Policies/PostPolicy.php
Open in GitHub<?php namespace App\Policies; use App\Models\Post; use App\Models\User; use Illuminate\Auth\Access\HandlesAuthorization; class PostPolicy { public function update(User $user, Post $post): bool { return $user->isAdmin(); } public function delete(User $user, Post $post): bool { return $user->isAdmin(); } }
-
app/Http/Controllers/Api/V1/PostController.php
Open in GitHubuse App\Http\Controllers\Controller; use App\Http\Requests\Admin\PostsRequest; use App\Http\Resources\Post as PostResource; use App\Models\Post; use Illuminate\Http\Request; use Illuminate\Http\Response; class PostController extends Controller { public function update(PostsRequest $request, Post $post): PostResource { $this->authorize('update', $post); $post->update($request->only(['title', 'content', 'posted_at', 'author_id', 'thumbnail_id'])); return new PostResource($post); } public function destroy(Post $post): Response { $this->authorize('delete', $post); $post->delete(); return response()->noContent(); } }