I have a index.blade.php page, I have a this code that shows alerts success or errors:
<!-- ALERTS -->
@if (isset($msg))
@if ($msg_type == 'error')
<div id="alert" class="alert alert-danger" role="alert">{{ $msg }}</div>
@else
<div id="alert" class="alert alert-success" role="alert">{{ $msg }}</div>
@endif
<script>setTimeout("document.getElementById('mensajecarrito').style.display='none'",6000);</script>
@endif
<!-- //ALERTS -->
This index have a form, and this form url POST to the post_designs url, and this is his controller method:
public function postDesign() {
if (Session::has('FUNCTION'))
$function = Session::get('FUNCTION');
if (Input::has('FUNCTION'))
$function = Input::get('FUNCTION');
if (isset($function))
{
switch($function)
{
case 'createDesign':
try
{
//do something good
$msg_type = 'success';
$msg = 'Design created successfully';
}
catch(FotiApiException $e)
{
$msg_type = 'error';
$msg = 'Unexpected error';
}
break;
}
}
return back()->with(array('msg' => $msg, 'msg_type' => $msg_type));
}
The problem is, that the $msg and $msg_type variables are empty when return back to my index.blade.php...
I don´t understand, my project is Laravel 5.2.3 and I have the correct route Middleware:
Route::group(['middleware' =>[ 'web']], function () {
# Index
Route::get('/',['as'=> 'index','uses' => 'WebController@getIndex']);
// # POSTS
Route::post('/post-design', ['as' => 'post_design', 'uses' => 'WebController@postDesign']);
});