Friday, May 4, 2018

Laravel – Route not defined - development

Laravel – Route not defined

I have a form that is using the Laravel forms package, the head of this form looks like this:



This form is inside the edit blade at views/users/edit.blade.php

To my knowledge 'route' => array('users.update', $user->$username) does the following:
finds a route with the name users.update and adds in the user’s username as a parameter.

Inside routes/web.php I have this:

Route::post('/users/{user}', 'UsersController@update')->name('users.update');

Given this I’m assuming the following:

The form goes to the named route and converts it into www.example.com/users/username

However, when I go to the edit page, which has the updating form inside of it, I get:

"Route [users.update] not defined. (View: C:xampphtdocsmy-newableresourcesviewsusersedit.blade.php)"

Even stranger is that when I run php artisan route:list the route in question is not even listed as a route that you can use within the application.

I have also tried the following command: php artisan route:cache

But it still doesn’t appear?

Finally, this is the update method with the UsersController

public function update(Request $request, User $user)
{  
    $user = User::findOrFail($user)->first(); 

    //Validate name, email and password fields  
    $this->validate($request, [

    ]);

    $roles = $request['roles']; //Retreive all roles

    if (isset($roles)) 
    {        
        $user->roles()->sync($roles);  //If one or more role is selected associate user to roles          
    }        
    else 
    {
        $user->roles()->detach(); //If no role is selected remove exisiting role associated to a user
    }

    return redirect()->route('users.index')->with('flash_message', 'User successfully edited.');
}

I’m just not seeing how the users.update method is not defined?



from Laravel Questions and Answers https://laravelquestions.com/php/laravel-route-not-defined/
via Lzo Media

No comments:

Post a Comment