路线:
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'];
}
}
编辑后类别重定向不会触发,我会停留在同一页面。如何解决它以及它不起作用的原因是什么?
答案 0 :(得分:2)
答案 1 :(得分:2)
使用顶部
use Illuminate\Support\Facades\Redirect;
和
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 Redirect('<PreviousControllerName>')->with($result); //Change It
}
return Redirect('/')->with($result); //Change It
}
答案 2 :(得分:1)
你应该退货:
return redirect('admin')->with($result);
答案 3 :(得分:0)
with
有两个参数
return redirect('/admin/')->with('result',$result);
答案 4 :(得分:0)
请您检查以下面的格式定义所有路线,然后尝试以适当的路线重定向
Route::group(array('prefix' => 'admin','middleware'=>'auth'), function() {
Route::post('student/cust_post', ['as' => 'admin.index', 'uses' => 'Admin\IndexController@index']
);
});
答案 5 :(得分:0)
你试过吗?
return redirect()->route('adminIndex');