Laravel split in blade pattern with nested foreach
I am retrieving an array of space-separated IDs as shown below.
@foreach($user_notify->user_notify_divisions as $user_notify)
{{$user_notify}}
@endforeach
Then the value of $ user_notify will be the identifier
$user_notify = 2 3 4 5
I have a database table section_list
id division_name
1 工業製品卸・小売
2 繊維・衣料製造
3 繊維・衣料卸・小売
4 食品製造
5 食品卸・小売
6 医薬品製造
Now how to get the division_name with the above id string
Thanks everyone!
source to share
As laravel
blade templating
you can do this as follows: nested foreach
.
Another problem in your code: you are iterating over $user_notify->user_notify_divisions
and define the value as $user_notify
, you should have a different variable name instead of the same name as for the object
@foreach($user_notify->user_notify_divisions as $user_notify)
{{$user_notify}}
@endforeach
Corrected code:
@foreach($user_notify->user_notify_divisions as $user_data)
@foreach(explode(" ",$user_data) as $ids)
{{$ids}}
@endforeach
@endforeach
source to share