gpt4 book ai didi

php - 商店后 Laravel 5 重定向

转载 作者:行者123 更新时间:2023-12-04 21:35:56 25 4
gpt4 key购买 nike

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

我的路线是

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

和 Controller 函数

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');
}

最佳答案

如果你想重定向到创建/更新的记录,你应该改变:

Vehicle::create($input);

进入:

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

现在:

return redirect('pages/aracislemler');

进入

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

关于php - 商店后 Laravel 5 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30742074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com