4

Is there a way in Laravel5 where I could define routes that handles dynamic routes without conflicting with current static routes? Something similar below:

// Dynamic routes
Route::get('{permalink}', function($permalink) {
   //look for matching username on the table (bind perhaps?)
});

// Static routes
Route::get('home', 'HomeController@index');
Route::get('products', 'ProductController@index');

Any ideas, guys? Thanks.

Jhourlad Estrella
  • 3,545
  • 4
  • 37
  • 66
  • I've unswered first question below. The serilization error is different from posted code. I guess you should look into your controllers or other classes to solve it. – Alexey Mezenin Feb 25 '16 at 18:20
  • You're right. Something else causes the error. The error is fixed now but the route is not. – Jhourlad Estrella Feb 26 '16 at 10:02
  • Great. But what problem with route do you have exactly (error or something)? Did you tried to put static routes before the dynamic ones? – Alexey Mezenin Feb 26 '16 at 10:03

1 Answers1

4

Static and dynamic routes shouldn't conflict with each other. Just put static routes higher than dynamic ones.

Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
  • Serialization of 'Closure' is not allowed. – Jhourlad Estrella Feb 25 '16 at 18:41
  • Yes, I wrote in the comments that your question about route conflict doesn't related to the error. Routes are fine. You should check your controller for errors. If you'll not be able to find it, you can update your post with some important parts of your controller and closure code. – Alexey Mezenin Feb 25 '16 at 18:45
  • Any idea why I am getting that error? It's originating from the first route. – Jhourlad Estrella Feb 25 '16 at 18:48
  • There can be a lot of reasons why you get this error. We can't help you without seeing actual code. – Alexey Mezenin Feb 25 '16 at 18:49
  • Sorry. I commented out everything else, leaving only this line: Route::get('foo', function() { return "bar!"; }); And still got the same error. – Jhourlad Estrella Feb 25 '16 at 18:56
  • Do you mean the only route in your \app\Http\routes.php is this one line and when you go to localhost/foo you get this error message? If so, I don't know how to help you, but I think this simple route can't give such error. – Alexey Mezenin Feb 25 '16 at 19:02