2016-09-27 13 views

答えて

0

ディスプレイ・セッションのメッセージコントローラから呼び出され

@if(Session::has('success')) 
    <div class="alert alert-success alert-dismissable alert-box"> 
    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</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">&times;</button> 
    {{ Session::get('error') }} 
    </div> 
@endif 

return redirect()->back()->with('success', 'Data added successfully'); 
+0

アラートで前後にボタンを押したときにアラートが複数回表示される –

0

セッションの不要な使用を避けてください。 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'); 
} 

これはあなたの疑問をクリア願っています。

上記の例は、私の最後でうまく動作します。これがあなたにとってうまくいかない場合は、コードを記述してください。

+0

作業中ではないので、$ strChecked値を表示できません。 –

+0

このコードに直面しているエラーを指定してください。 –

+0

$ strCheckedの値は未定義です。jQueryまたはユーザが書かれたページ内のどこにでも書かれているため、未定義です –

関連する問題