Reputation: 237
Routes:
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);
}
Model:
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'];
}
}
After editing category redirect doesn't trigger and i stay in same page. How to fix it and what is the reason why it doesn't work?
Upvotes: 5
Views: 6017
Reputation: 34924
with
has two parameters
return redirect('/admin/')->with('result',$result);
Upvotes: 0
Reputation:
Could you please check with defining all your Routes in below format and then try redirecting in appropriate route
Route::group(array('prefix' => 'admin','middleware'=>'auth'), function() {
Route::post('student/cust_post', ['as' => 'admin.index', 'uses' => 'Admin\IndexController@index']
);
});
Upvotes: 0
Reputation: 119
Use At Top
use Illuminate\Support\Facades\Redirect;
and
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
}
Upvotes: 2
Reputation: 18577
return redirect,
return redirect('/admin')->with(compact('result'));
Here is the link.
It should work.
Upvotes: 2
Reputation: 163968
You should return it:
return redirect('admin')->with($result);
Upvotes: 1