今天我尝试在Laravel 5.2.35项目中设置Session::flash('alert-info', 'This is a message')
。但它不会显示。
我从web
删除了routes.php
中间件。但它仍然无效。
Routes.php
Route::group(['prefix' => 'client/{administration_id}', 'middleware' => ['loggedin']], function() {
Route::get('/projects', ['as' => 'client.projects', 'uses' => 'ProjectController@listProjects']);
Route::get('/project/new', ['as' => 'client.project.create', 'uses' => 'ProjectController@newProject']);
Route::post('/project/new', ['as' => 'client.project.create.save', 'uses' => 'ProjectController@saveNewProject']);
});
ProjectController.php
<?php
namespace App\Http\Controllers;
use App\Projects;
use App\Http\Requests;
use Session;
class ProjectController extends Controller
{
public function newProject($administration_id) {
$customers = Customer::where('administration_id', $administration_id)->get();
return view('client.projects.create', compact('customers'));
}
public function saveNewProject(Request $request, $administration_id) {
$project = new Projects();
$project->name = $request->name;
$project->project_number = $request->code;
$project->administration_id = $administration_id;
$project->customer_id = $request->customer;
if($project->save()) {
Session::flash('alert-info', trans('projects.projects.create.success'));
return redirect(route('client.projects', $administration_id));
} else {
Session::flash('alert-warning', trans('projects.projects.create.failure'));
return redirect()->back();
}
}
}
Kernel.php
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
],
'loggedin' => [
'auth',
],
'api' => [
'throttle:60,1',
],
];
答案 0 :(得分:0)
我从middleware web
删除了RouteServiceProvider.php
。
旧代码:
protected function mapWebRoutes(Router $router)
{
$router->group([
'namespace' => $this->namespace, 'middleware' => 'web',
], function ($router) {
require app_path('Http/routes.php');
});
}
新代码:
protected function mapWebRoutes(Router $router)
{
$router->group([
'namespace' => $this->namespace,
], function ($router) {
require app_path('Http/routes.php');
});
}
在此之后它工作正常,我不知道其他人是否有同样的问题,但也许这可能是一个解决方案。