Skip to content

Instantly share code, notes, and snippets.

@suehok
Last active July 19, 2019 03:10
Show Gist options
  • Save suehok/c0a7aca616efb54b57dca33553272952 to your computer and use it in GitHub Desktop.
Save suehok/c0a7aca616efb54b57dca33553272952 to your computer and use it in GitHub Desktop.
Create new custom action in app/Actions/PublishAction.php
<?php
namespace App\Actions;
use TCG\Voyager\Actions\AbstractAction;
class PublishAction extends AbstractAction
{
public function getTitle()
{
// Action title which display in button based on current status
return $this->data->{'status'}=="PUBLISHED"?'Pending':'Publish';
}
public function getIcon()
{
// Action icon which display in left of button based on current status
return $this->data->{'status'}=="PUBLISHED"?'voyager-x':'voyager-external';
}
public function getAttributes()
{
// Action button class
return [
'class' => 'btn btn-sm btn-primary pull-left',
];
}
public function shouldActionDisplayOnDataType()
{
// show or hide the action button, in this case will show for posts model
return $this->dataType->slug == 'posts';
}
public function getDefaultRoute()
{
// URL for action button when click
return route('posts.publish', array("id"=>$this->data->{$this->data->getKeyName()}));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment