Created
July 19, 2019 03:37
-
-
Save suehok/410ec1cf758f6ca947ec646a5620f1e0 to your computer and use it in GitHub Desktop.
PostController to handle the custom publish action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers\Voyager; | |
use TCG\Voyager\Http\Controllers\VoyagerBaseController; | |
use TCG\Voyager\Models\Post; | |
class PostController extends VoyagerBaseController | |
{ | |
public function publish(){ | |
//Get post by id and toggle the status from PUBLISHED to PENDING and vice versa | |
$post = Post::where('id', \request("id"))->first(); | |
$post->status = $post->status=="PENDING"?"PUBLISHED":"PENDING"; | |
$post->save(); | |
return redirect(route('voyager.posts.index')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment