无法在警告框中显示值,Laravel
Unable to show value inside alert box, Laravel
我试图在我的视图中显示从控制器传递到我的警报框的值。
我使用了以下代码来显示,但它不起作用。
@foreach($student as $student)
@include('widgets.alert', array('class'=>'info', 'message'=> 'Creating Bill for: {!!$student->first_name!!}'))
@endforeach
如果我直接尝试显示如下值:
@foreach($student as $student)
<h4>Creating Bill for: {{$student->first_name}}</h4>
@endforeach
效果很好。谁能给我解决方案?
您需要稍微更改变量,因为当您在 foreach 循环中 运行 $student
时,它将覆盖包含所有学生的数组。
更改它并让它起作用的最简单方法是:
将第一个$student
改为$students
。
@foreach($students as $student)
<h4>Creating Bill for: {{$student->first_name}}</h4>
@endforeach
@foreach($students as $student)
@include('widgets.alert', array('class'=>'info', 'message'=> 'Creating Bill for: '.$student->first_name))
@endforeach
当然,在您的 Controller
中,您需要将发送到 view
的变量从 $student
更改为 $students
。
希望这有效!
我试图在我的视图中显示从控制器传递到我的警报框的值。 我使用了以下代码来显示,但它不起作用。
@foreach($student as $student)
@include('widgets.alert', array('class'=>'info', 'message'=> 'Creating Bill for: {!!$student->first_name!!}'))
@endforeach
如果我直接尝试显示如下值:
@foreach($student as $student)
<h4>Creating Bill for: {{$student->first_name}}</h4>
@endforeach
效果很好。谁能给我解决方案?
您需要稍微更改变量,因为当您在 foreach 循环中 运行 $student
时,它将覆盖包含所有学生的数组。
更改它并让它起作用的最简单方法是:
将第一个$student
改为$students
。
@foreach($students as $student)
<h4>Creating Bill for: {{$student->first_name}}</h4>
@endforeach
@foreach($students as $student)
@include('widgets.alert', array('class'=>'info', 'message'=> 'Creating Bill for: '.$student->first_name))
@endforeach
当然,在您的 Controller
中,您需要将发送到 view
的变量从 $student
更改为 $students
。
希望这有效!