weird problem in web.php

Hi there,

I'm writing routes in web.php but I got a problem. If the code is

Route::get('articles/create', '[email protected]');
Route::get('articles/{id}', '[email protected]'); 

then the "articles/create" will working properly with giving me a page (which links to a blade.php)

However, if I swap these 2 lines like

Route::get('articles/{id}', '[email protected]'); 
Route::get('articles/create', '[email protected]');

Then I will get an error which shows "Trying to get property of non-object (View: D:\xampp\htdocs\laravel\resources\views\articles\single.blade.php)".

The single.blade.php is returned by "[email protected]" method.

(I'm just following this tutorial "Laravel 5 Fundamentals: Forms" from Hopefully I described clearly.

Need help with this. Did I miss any code there?

Thank you,


ilinovster replied 4 months ago
Route::get('articles/create', '[email protected]');
Route::get('articles/{id}/show', '[email protected]');
GarlicBread replied 4 months ago

Ye the solution above works!

So it is updated in 5.4? I mean, need something after "{id}"?

ilinovster replied 4 months ago Solution

No, it isn't updated in 5.4. Route 'aticles/create' is synonymous with route 'articles/{id}'. Imagine that id === 'create'... Routes must are uniques. Another variant is:

Route::get('articles/create', '[email protected]');
Route::get('articles/show/{id}', '[email protected]');
GarlicBread replied 3 months ago

OH! I see! That makes sense.

Thank you!

Y Joy Singha replied 3 months ago

GarlicBread: Your problem is not in the route of web.php, problem is in your ArticlesController, check the data that you assign in your ArticlesController to view in your single.blade.php, it will work for sure.

Sign in to participate in this thread!

We'd like to thank these amazing companies for supporting us