Laravel 5 商店后重定向

Laravel 5 redirect after store

如何在 L5 的存储过程后重定向路由?

我的路线是

Route::get('/pages/aracislemler/{id}', ['middleware' => ['roles'], 'uses' => 'PagesController@aracislemler', 'roles' => ['Admin']]);

和控制器功能

public function store()
{

        $brand_name = Request::get('brand_id');
        $type_id = Request::get('type_id');
        //$client_id = Request::get('representive_client_id');

        if (!Brand::find($brand_name)) {
            $brand = new Brand;
            $brand -> brand_name = $brand_name;
            $brand -> type_id = $type_id;
            $brand -> save();

            $last_brand_id = $brand -> id;

            $input = Request::except('brand_id');
            Vehicle::create($input);

            $vehicle = Vehicle::orderBy('created_at', 'desc')->first();
            $vehicle -> update(array('brand_id' => $last_brand_id));

        }else{         
            $input = Request::all();
            Vehicle::create($input);
        }

        return  redirect('pages/aracislemler');
}

如果你想重定向到 created/updated 的记录,你应该更改:

Vehicle::create($input);

进入:

$vehicle = Vehicle::create($input);

现在:

return redirect('pages/aracislemler');

进入

return redirect('pages/aracislemler/'.$vehicle->id);

我是这样做的:

我的路线:

Route::resource('portal', 'PortalController');
Route::resource('show', 'PortalController');

PortalController: (存储函数)

$portalNewID = $portal->id; //I retrieved the last ID
return redirect('portal/'.$portalNewID); //This will redirect to the latest page you just created

希望对您有所帮助。