gpt4 book ai didi

php - 重定向在 laravel 5 中不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:34:36 25 4
gpt4 key购买 nike

路线:

Route::group(['prefix'=>'admin','middleware'=>'auth'],function(){
Route::get('/',['uses'=>'Admin\IndexController@index','as'=>'adminIndex']);
Route::resource('/cat-n-cat','Admin\CatalogsNCategoriesController');
});

Controller :

public function update($data)
{
$category = Category::find($data[0]['id']);
$result = $this->category_rep->updateCategory($data,$category);
if (is_array($result) && !empty($result['error'])) {
return back()->with($result);
}
redirect('admin')->with($result);
}

型号:

public function updateCategory($data,$category){
$data=$data[0];
if (empty($data)) {
return array('error' => 'No data');
}
$result = $this->one($data['name']);
if (isset($result->id) && ($result->id != $category->id)) {
return ['error' => 'Category with this name already exists'];
}
$category->fill($data);
if($category->update()){
return ['status' => 'Category has been added'];
}
}

编辑类别重定向后不会触发,我停留在同一页面。如何修复它以及它不起作用的原因是什么?

最佳答案

返回重定向,

return redirect('/admin')->with(compact('result')); 

这是 link .

它应该可以工作。

关于php - 重定向在 laravel 5 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42672274/

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