Add delete function to TagPolicy to protect destroy@TagsController
MODIFY
app/Http/Controllers/TagsController.php
app/Http/Controllers/TagsController.php
@@ -41,9 +41,7 @@ class TagsController extends Controller {
return redirect()->route('tags');
}
- public function destroy($id) {
- $tag = Tag::find($id);
-
+ public function destroy(Tag $tag) {
$tag->delete();
return redirect()->route('tags');

MODIFY
app/Policies/TagPolicy.php
app/Policies/TagPolicy.php
@@ -9,4 +9,8 @@ class TagPolicy {
public function update(User $user, Tag $tag) {
return $user->id === $tag->user_id;
}
+
+ public function delete(User $user, Tag $tag) {
+ return $user->id === $tag->user_id;
+ }
}

MODIFY
routes/web.php
routes/web.php
@@ -31,7 +31,7 @@ Route::group(['middleware' => ['auth']], function () {
Route::post('/tags', 'TagsController@store');
Route::get('/tags/{tag}/edit', 'TagsController@edit')->name('tags.edit')->middleware('can:update,tag');
Route::patch('/tags/{tag}', 'TagsController@update')->middleware('can:update,tag');
- Route::delete('/tags/{id}', 'TagsController@destroy')->name('tags.destroy');
+ Route::delete('/tags/{tag}', 'TagsController@destroy')->name('tags.destroy')->middleware('can:delete,tag');
Route::get('/settings', 'SettingsController@index')->name('settings');
Route::post('/settings', 'SettingsController@store');

Add delete function to TagPolicy to protect destroy@TagsController