Laravel 5 Routing Calling Wrong View

I have a simple Laravel 5 site that I am working on (learning Laravel)

I have a link in my view of users to add a "new user":

<a href="{{ url('/user/create') }}">Create New User</a>


My user Routes looks like this:

Route::get('/users', 'UserController@index');
Route::get('/user/{id}', 'UserController@edit');
Route::get('/user/create', 'UserController@create');
Route::get('/user/update', 'UserController@update');
Route::get('/user/delete/{id}', 'UserController@delete');


My UsersController has this:

 * Display a listing of the resource.
 * @return Response
public function index()
    $users = user::all();
    return view('user.index',compact('users'));

 * Show the form for creating a new resource.
 * @return Response
public function create()
    $userroles = userrole::all();
    return view('user.create', compact('userroles'));


When I click the link - I get the following error:

Trying to get property of non-object (View: C:\xampp\htdocs\mysite\resources\views\user\edit.blade.php)


I cannot figure out why it is trying to load edit.blade.php

I tried to just put the following in my creation view and it still doesn't display.




I'm not sure why the routing is so weird.

Any ideas?


source to share

1 answer

Place the create (and update) route before the edit route in the routes file. Laravel 1 stumbles upon the edit route and treats create

as id.

You can test it by executing dd($id)

in your edit method in the controller.



All Articles