In order to avoid duplicating logic within my form views, I decided to take advantage of Blade's custom directives and create a directive to clean up my views a bit.
So rather than this:
{{ in_array( 'Miami', old('city) ) ? 'selected' : '' }}
on every select option, I can just say:
@selected('Miami', old('city'))
However, when using this new directive, I'm consistently getting an error:
Too few arguments to function Providers\{closure}(), 1 passed and exactly 2 expected
In attempting to diagnose this issue, I realized that the old() function is sending a null value for old('city'), even though it SHOULD contain an array of values.
I'm not sure why this is happening, however, I have some ideas as to why it might.
Has anybody else run into this issue? And if this can't be done, what would be the best way to avoid having to duplicate this logic on forms without using a custom directive?
Thanks!