Skip to content

Instantly share code, notes, and snippets.

@suehok
Created July 19, 2019 03:37
Show Gist options
  • Save suehok/410ec1cf758f6ca947ec646a5620f1e0 to your computer and use it in GitHub Desktop.
Save suehok/410ec1cf758f6ca947ec646a5620f1e0 to your computer and use it in GitHub Desktop.
PostController to handle the custom publish action
<?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