问题描述:

Using Laravel and the "Bootstrapper" module ("patricktalmadge/bootstrapper").

Have searched the web and SO over and cannot find the correct way to pass optional attributes to things like "buttons".

For example:

$iconRemove = Button::primary([

'data-id' => $root->id

])

->prependIcon(Icon::remove());

Obviously the variable $root->id would be a record number, so what I am trying to pass would end up looking somehting like:

$iconRemove = Button::primary([

'data-id' => 2

])

->prependIcon(Icon::remove());

This seems like this should be possible, but I can find no comparable example.

Instead, I get the error

An exception of type ErrorException was thrown with the message: Array

to string conversion

Anyone no the best practice for solving this problem using this module or a better practice / module for generating Twitter Bootstrap components in Laravel that would enable this?

网友答案:

I don't know the package but from scanning the source quickly I can see that the Button::primary method takes only one parameter. Which is the label of the button.

You can add other attributes though, by using addAttributes() (or withAttributes(), add is an alias)

Button::primary('Text')
            ->addAttributes([
                'data-id' => $root->id
            ])
            ->prependIcon(Icon::remove());
相关阅读:
Top