yaddly's avatar
Level 2

Passing named arguments to include blade directive throws error

Good day laracons, I encountered a peculiar phenomenon while I was doing a tutorial. I used the include blade directive as below and it throw a fatal error 'Cannot use positional argument after named argument'. However, removing the named arguments resolves the error, however, it makes the code hard to read or nebulous.

Throws Error:

@include(view: 'components.partial-views.input', data: ['input_name' => 'company-name', 'input_id' => 'company-name'])

Simple Fix:

@include('components.partial-views.input', ['input_name' => 'company-name', 'input_id' => 'company-name'])

Is this a bug or there is something genuinely wrong with my code?

0 likes
6 replies
yaddly's avatar
Level 2

@tisuchi Thank you for pointing me to the documentation for insights

yaddly's avatar
Level 2

@JussiMannisto Thank you for your invaluable comments and directing me to the repo to examine the code.

Snapey's avatar

I woukd probably rewrite as a component where you can use similar nemed parameters

yaddly's avatar
Level 2

@Snapey Thank you for your insights but this would be too much work that achieves so little. I find named parameters making code more elegantly readable.

Please or to participate in this conversation.