Last active
July 19, 2019 03:10
-
-
Save suehok/c0a7aca616efb54b57dca33553272952 to your computer and use it in GitHub Desktop.
Create new custom action in app/Actions/PublishAction.php
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\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