上で複数回表示されますLaravelセッションフラッシュメッセージは、私のコントローラでpageback
@if(Session::has('created'))
alert('updated');
@endif
上で複数回表示されますLaravelセッションフラッシュメッセージは、私のコントローラでpageback
@if(Session::has('created'))
alert('updated');
@endif
ディスプレイ・セッションのメッセージコントローラから呼び出され
@if(Session::has('success'))
<div class="alert alert-success alert-dismissable alert-box">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
{{ Session::get('success') }}
</div>
@endif
@if(Session::has('error'))
<div class="alert alert-danger alert-dismissable alert-box">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
{{ Session::get('error') }}
</div>
@endif
return redirect()->back()->with('success', 'Data added successfully');
アラートで前後にボタンを押したときにアラートが複数回表示される –
セッションの不要な使用を避けてください。 Redirect::routeを使用できます。以下の例を確認してください:
1)$strChecked = false;
を生徒ルートコントローラに初期設定してから、$strChecked = true;
を学生の更新方法に設定してください。
2)return \Redirect::route('student')->with('strChecked', $strChecked);
3を使用して戻りラインを交換してください)次に、あなたのビューで、あなたが使用することができます。
@if($strChecked)
alert('updated');
@endif
EDITS:
は私が私の作業のデモコードを示してみよう:
1)ROUTE:
Route::get('flash', '[email protected]')->name('frontend.flash');
Route::post('flash/update', '[email protected]')->name('frontend.flash.update');
2)VIEW:
@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)CONTROLLER:
//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');
}
これはあなたの疑問をクリア願っています。
上記の例は、私の最後でうまく動作します。これがあなたにとってうまくいかない場合は、コードを記述してください。
作業中ではないので、$ strChecked値を表示できません。 –
このコードに直面しているエラーを指定してください。 –
$ strCheckedの値は未定義です。jQueryまたはユーザが書かれたページ内のどこにでも書かれているため、未定義です –
あなたの質問は正確ですか? – Nil
なぜセッションを使用していますか?より良い解決策としてRedirect :: route()メソッドを使用することができます。 –