php-Laravel在刀片模板中拆分嵌套的foreach
作者:互联网
我检索由空格分隔的ID数组,如下所示
@foreach($user_notify->user_notify_divisions as $user_notify)
{{$user_notify}}
@endforeach
然后$user_notify的值将是ID
$user_notify = 2 3 4 5
我有一个数据库表division_list
id division_name
1 工業製品卸・小売
2 繊維・衣料製造
3 繊維・衣料卸・小売
4 食品製造
5 食品卸・小売
6 医薬品製造
现在如何使用上面的id字符串获取Division_name
感谢大家!
解决方法:
在laravel刀片模板中,您可以像嵌套的foreach一样进行操作.
代码中的另一个问题是,您正在$user_notify-> user_notify_divisions上进行迭代,并将值定义为$user_notify,您应该使用不同的变量名而不是对象名
@foreach($user_notify->user_notify_divisions as $user_notify)
{{$user_notify}}
@endforeach
更正的代码:
@foreach($user_notify->user_notify_divisions as $user_data)
@foreach(explode(" ",$user_data) as $ids)
{{$ids}}
@endforeach
@endforeach
标签:laravel,split,blade,arrays,php 来源: https://codeday.me/bug/20191111/2019679.html