Laravel split in blade template nested foreach

arrays, laravel, laravel-blade, php, split

Solution

In `laravel` `blade templating` you can do it like this `nested foreach`.

Another problem in your code is, you are iterating on `$user_notify->user_notify_divisions` and defining value as `$user_notify` you should have different variable name instead of same name as of 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

Problem

I retrieve an array of IDs separated by white space as shown below ``` @foreach($user_notify->user_notify_divisions as $user_notify) {{$user_notify}} @endforeach ``` Then the value of $user_notify will be the ID ``` $user_notify = 2 3 4 5 ``` I have a database table division_list ``` id division_name 1 工業製品卸・小売 2 繊維・衣料製造 3 繊維・衣料卸・小売 4 食品製造 5 食品卸・小売 6 医薬品製造 ``` Now how to get division_name with the above id string Thanks everyone!

Original source