DEV Community

Laravel Nova: Adding custom buttons to resource toolbars

Jake Casto on March 14, 2019

If you've seen issue 786 on laravel/nova-issues on Github or attempted to add custom buttons to Resources in Laravel Nova you are probably frustra...
Collapse
 
palpalani profile image
Palaniappan

Hi,

I want try this tool,but when install i am getting the following namespace parser error.

In ToolServiceProvider.php line 3:

syntax error, unexpected '0x15f' (T_LNUMBER), expecting identifier (T_STRING)
Enter fullscreen mode Exit fullscreen mode
Collapse
 
emillkaakillme profile image
Emil

Fixed!
Just removed a vendor dir in project (rm -rf vendor)
Then run composer update

And try to create a new nova resourse-tool with following command:
php artisan nova:resource-tool my-vendor-name/custom-resource-toolbar

'my-vendor-name' should be in kebab case

It helped me, hope it will help you

Collapse
 
emillkaakillme profile image
Emil

After I run your command:
php artisan nova:resource-tool 0x15f/custom-resource-toolbar
The artisan in my project stopped working...

It always reports an error with this wierd thing

In case if you know how to fix it please let me know!

Collapse
 
briavers profile image
Brian Verschoore

what do you mean with add it to your Resources?

Collapse
 
camaech profile image
Cam Heikkinen

This is the important part: "You can define your resources toolbar component by registering a component with your resources plural name followed by -detail-toolbar."

So in my case, I was using for an Article nova resource. So I changed the 'quotes-detail-toolbar' to 'articles-detail-toolbar'. That's it. You don't even need to add it as a tool, like you do with most other Nova tools in your NovaServiceProvider.

The button will now show up in your Resource (url should be something like: '/resources/articles/76'), assuming you ran 'npm run dev' on your tool.

Collapse
 
hemnyos profile image
Hemnyos

hi ! i'm so sorry, i'm learning laravel and i dont understand where i can add my button. I mean i did all of things at top, but event a random button doesnt appeared x3

Collapse
 
jake profile image
Jake Casto

Yes! When you add the resource tool to the model use the canSee method you use to hide fields and stuff. More info here

Collapse
 
it3krakow profile image
IT-3

Hello,
great job !
I do this in the Index page - and it works perfectly!
I have one question, maybe you have any idea how to add to button permissions?
On the detail page I can use withMeta method, but is there any way to pass the permission to do the action on index page ?

Collapse
 
milkhan profile image
Milkhan

Thank you for this tutorial but can you please explain how to use this on a resource? Thank you!

Collapse
 
camaech profile image
Cam Heikkinen

This is the important part: "You can define your resources toolbar component by registering a component with your resources plural name followed by -detail-toolbar."

So in my case, I was using for an Article nova resource. So I changed the 'quotes-detail-toolbar' to 'articles-detail-toolbar'. That's it. You don't even need to add it as a tool, like you do with most other Nova tools in your NovaServiceProvider.

The button will now show up in your Resource (url should be something like: '/resources/articles/76'), assuming you ran 'npm run dev' on your tool.

Collapse
 
ibet7o profile image
Roberto Ramírez

This is really simple! thank you very much.