0

i am trying to return back to departments after add a new department but this what happens :

Route [admin.departments.index] not defined

this is my store function in the DepartmentController

class DepartmentController extends BaseController
{
  public function store(Request $request)
 {
    $this->validate($request, [
        'department_name'      =>  'required|max:191',
    ]);

    $params = $request->except('_token');

    $department = $this->departmentRepository->createDepartment($params);

    if (!$department) {
        return $this->responseRedirectBack('Error occurred while creating department.', 'error', true, true);
    }
    return $this->responseRedirect('admin.deparments.index', 'Department added successfully' ,'success',false, false);
}

}

this is the responseRedirect function in the base controller

 class BaseController extends Controller
 {
  protected function responseRedirect($route, $message, $type = 'info', 
   $error = false, $withOldInputWhenError = false)
     {
    $this->setFlashMessage($message, $type);
    $this->showFlashMessages();

    if ($error && $withOldInputWhenError) {
        return redirect()->back()->withInput();
    }

    return redirect()->route($route);
   }
}

these are the routes

Route::group(['prefix' => 'departments'], function() {

        Route::get('/', 'Admin\DepartmentController@index')->name('admin.departments.index');
        Route::get('/create', 'Admin\DepartmentController@create')->name('admin.departments.create');
        Route::post('/store', 'Admin\DepartmentController@store')->name('admin.departments.store');
        Route::get('/{id}/edit', 'Admin\DepartmentController@edit')->name('admin.departments.edit');
        Route::post('/update', 'Admin\DepartmentController@update')->name('admin.departments.update');
        Route::get('/{id}/delete', 'Admin\DepartmentController@delete')->name('admin.departments.delete');

 });

InvalidArgumentException
Route [admin.deparments.index] not defined.

1
  • Always check for the typo first and copy and paste the errors, not write it yourself. Commented Aug 27, 2019 at 6:37

1 Answer 1

2

The store function in your DepartmentController returns a typo: admin.deparments.index should be admin.departments.index.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.