Redirection does not work laravel 5

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 the category, the redirection does not start, and I remain on one page. How to fix it and why does it not work?

+4
source share
6 answers

return redirect,

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

Here's the link .

It should work.

+2
source

Top use

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
}
+2
source

:

return redirect('admin')->with($result);
+1

with

 return redirect('/admin/')->with('result',$result);
0

, .

Route::group(array('prefix' => 'admin','middleware'=>'auth'), function() {
    Route::post('student/cust_post', ['as' => 'admin.index', 'uses' => 'Admin\IndexController@index']
    );
});
0

?

return redirect()->route('adminIndex');
0

Source: https://habr.com/ru/post/1671806/


All Articles