cms/app/Http/Controllers/Admin/Posts/PostUpdateController.php

34 lines
1 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Http\Controllers\Admin\Posts;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\Posts\UpdatePostRequest;
use App\Models\CustomPostType;
use App\Models\Post;
use App\Services\PostService;
use Illuminate\Http\RedirectResponse;
/**
* Controller for updating an existing post.
*/
class PostUpdateController extends Controller
{
/**
* Update the specified post.
*
* @param \App\Http\Requests\Admin\Posts\UpdatePostRequest $request
* @param \App\Models\CustomPostType $customPostType
* @param \App\Models\Post $post
* @param \App\Services\PostService $service
* @return \Illuminate\Http\RedirectResponse
*/
public function __invoke(UpdatePostRequest $request, CustomPostType $customPostType, Post $post, PostService $service): RedirectResponse
{
$service->updatePost($post, $request->validated());
return redirect()->route('admin.posts.index', $customPostType->slug)
->with('success', $customPostType->singular_name . ' updated successfully.');
}
}