Customize blade directive to allow changing the div id #186
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While reading through #141 and #178 I noticed the
$expression
that's passed by the blade compiler wasn't treated as a PHP expression, but rather as a string. I think this should be treated as an expression to follow blade standards and this will allow people to conditionally change the id like so@inertia(true ? 'foo' : 'bar')
.This means
@inertia(foo)
is not allowed, since that's not a valid expression. However, all directives mentioned in the blade docs have valid PHP as parameter for the blade directives ('title'
,count($records) === 1
) and for exampleyield(content)
wouldn't work either since that doesn't contain a valid PHP expression.The easiest solution is to output the expression in the directive directly to pass that to a method call, so the directive would return this
'<?php echo app(\MyClass::class)->render('.$expression.'); ?>'
. This works as expected, unfortunately Inertia also needs to output the$page
variable which is passed as view data. I've tried to come up with a solution for this, but this is far from perfect, since I don't really like the usage of an anonymous class for this. Maybe someone can help me figure out a better solution, or this PR can be used to improve one of the other PR'sOh and I used @claudiodekker's tests from #141, so I added you as co-author :)