When using:
$this->crud->addButtonFromModelFunction($stack, $name, $model_function_name, $position);
this error show:
Undefined variable: entry
the entry value is null and i think the problem coming from "button_stack.blade":
{!! $entry->{$button->content}(); !!}
Hi @MDEvo ,
I have it working correctly in a few projects. Could you please copy-paste your api call (addButtonFromModelFunction) to figure out what's happening?
Cheers!
Try this two also throw the same error:
$this->crud->addButton('top', 'create5', 'model_function', 'getCreateButtonHtml', 'end');
$this->crud->addButtonFromModelFunction('top', 'create5', 'getCreateButtonHtml', 'end');
ErrorException in 952a59389f3e3cb5c3643a31c8a820553b244955.php line 4: Undefined variable: entry (View: C:\xampp2\htdocs\laravel-bp54\vendor\backpack\crud\src\resources\views\inc\button_stack.blade.php) (View: C:\xampp2\htdocs\laravel-bp54\vendor\backpack\crud\src\resources\views\inc\button_stack.blade.php)
Model:
public function getCreateButtonHtml() {
return "<a href='#'>Test</a>";
}
Find the culprit. It is because the $entry value is null since the 'top' button stack don't have any entry defined in list view. If I change the stack to 'line' it is work.
So, the :
{!! $entry->{$button->content}(); !!}
in "button_stack.blade" only work in 'line' stack ONLY.
Top or Bottom stack should work by modifying something like :
{!! $crud->model->{$button->content}(); !!}
Full:
@if ($button->type == 'model_function')
@if ($stack == 'line')
{!! $entry->{$button->content}($entry); !!}
@else
{!! $crud->model->{$button->content}($crud); !!}
@endif
@else
@include($button->content)
@endif
Oh, I understand.
Well, it makes sense - if a button is in the top or bottom stack there is no entry. They're just general buttons.
Glad you figuured it out. Cheers!
Then maybe the template should be updated?
https://github.com/Laravel-Backpack/CRUD/blob/master/src/resources/views/inc/button_stack.blade.php
Hi @victorlap ,
I'm sorry, I don't think I understand. What should we update in the template?
Cheers and thanks!
@tabacitu you need to update the button_slack.blade.php in order the "top" will work.
Agree with @victorlap. I have to overwrite each time the button_stack template on each project.
This fix allow us to access a model function even if we're on the "top" stack, without create a new view.
@Mortred974 , @victorlap , sorry, it seems like I'm was being really dumb here :-) The way I saw it, the problem was not in button_stack.blade.php. It's was in the view file when someone creates a new button. In that view file, $entry made no sense, since there's no entry. I did NOT notice you were talking about the model_function button...
I have now seen that, AND @MDEvo 's suggestion. Just made the change in the current version (3.3.3), will be available to everyone as a patch update later today when it's released.
Thanks for sticking with me through this - I be dumb sometimes :-)
Most helpful comment
Then maybe the template should be updated?
https://github.com/Laravel-Backpack/CRUD/blob/master/src/resources/views/inc/button_stack.blade.php