请避免不必要地使用会话。您可以使用Redirect::route。检查以下示例:
1) 将$strChecked = false; 初始化到你的学生路由控制器,然后将$strChecked = true; 设置到你的学生更新方法中。
2) 用return \Redirect::route('student')->with('strChecked', $strChecked);替换您的退货行
3) 那么在你看来,你可以使用:
@if($strChecked)
alert('updated');
@endif
编辑:
让我用我的工作演示代码来说明:
1) 路线:
Route::get('flash', 'FlashController@flashIndex')->name('frontend.flash');
Route::post('flash/update', 'FlashController@studentUpdate')->name('frontend.flash.update');
2) 查看:
@section('content')
{{ Form::open(['route' => 'frontend.flash.update', 'class' => 'form-horizontal']) }}
{{ Form::submit('Demo', ['class' => 'btn btn-primary', 'style' => 'margin-right:15px']) }}
{{ Form::close() }}
@endsection
@section('after-scripts-end')
<script>
@if(Session::has('created'))
alert('updated');
@endif
</script>
@stop
3) 控制器:
//Method to display action...
public function flashIndex()
{
return view('frontend.flash');
}
//Method to update action...
public function studentUpdate()
{
Session::flash('created', "Student created");
return Redirect::to('flash');
}
希望这能消除您的疑虑。
上面的例子在我的最后工作正常。如果这不适合您,请描述您的代码。