【发布时间】:2016-08-31 19:30:15
【问题描述】:
我有一个 index.blade.php 页面,我有一个显示警报成功或错误的代码:
<!-- 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 -->
这个index有一个form,这个form url POST到post_designs url,这是他的controller方法:
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));
}
问题是,当返回我的 index.blade.php 时,$msg 和 $msg_type 变量是空的...
我不明白,我的项目是 Laravel 5.2.3,我有正确的路由中间件:
Route::group(['middleware' =>[ 'web']], function () {
# Index
Route::get('/',['as'=> 'index','uses' => 'WebController@getIndex']);
// # POSTS
Route::post('/post-design', ['as' => 'post_design', 'uses' => 'WebController@postDesign']);
});
【问题讨论】:
标签: php laravel laravel-5.2