35 lines
1.1 KiB
PHP
35 lines
1.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Admin\Posts;
|
||
|
|
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Models\CustomPostType;
|
||
|
|
use App\Models\Post;
|
||
|
|
use App\Services\PostService;
|
||
|
|
use Illuminate\Http\RedirectResponse;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Controller for deleting an existing post.
|
||
|
|
*/
|
||
|
|
class PostDestroyController extends Controller
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Remove the specified post.
|
||
|
|
*
|
||
|
|
* @param \App\Models\CustomPostType $customPostType
|
||
|
|
* @param \App\Models\Post $post
|
||
|
|
* @param \App\Services\PostService $service
|
||
|
|
* @return \Illuminate\Http\RedirectResponse
|
||
|
|
*/
|
||
|
|
public function __invoke(CustomPostType $customPostType, Post $post, PostService $service): RedirectResponse
|
||
|
|
{
|
||
|
|
if ($service->deletePost($post)) {
|
||
|
|
return redirect()->route('admin.posts.index', $customPostType->slug)
|
||
|
|
->with('success', $customPostType->singular_name . ' deleted successfully.');
|
||
|
|
}
|
||
|
|
|
||
|
|
return redirect()->route('admin.posts.index', $customPostType->slug)
|
||
|
|
->with('error', 'Failed to delete ' . $customPostType->singular_name . '.');
|
||
|
|
}
|
||
|
|
}
|