【发布时间】:2017-03-08 13:10:05
【问题描述】:
路线:
Route::group(['prefix'=>'admin','middleware'=>'auth'],function(){
Route::get('/',['uses'=>'Admin\IndexController@index','as'=>'adminIndex']);
Route::resource('/cat-n-cat','Admin\CatalogsNCategoriesController');
});
控制器:
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'];
}
}
编辑类别重定向后不会触发,我停留在同一页面。如何修复它,它不起作用的原因是什么?
【问题讨论】:
-
你试过这样返回redirect('admin')->with($result);
-
还是不行:c
-
你遇到了什么错误
-
有什么错误吗?
-
@rahul_m 没有错误,只是仍然停留在同一页面,没有重定向
标签: php laravel redirect model controller