Support the ongoing development of Laravel.io →
posted 9 years ago
Requests
Last updated 1 year ago.
0

Syntax errors.

Route::get('sale_add_item/{alias}/{item_id}', function($alias, $item_id)
{
});
Last updated 1 year ago.
0

$item_id is an optional parameter, so i need to leave {item_id?}. Am i wrong?

Last updated 1 year ago.
0

Try this :

Route::get('sale_add_item/{alias}/{item_id?}', function($alias, $item_id=null) {
    
})->where('alias', '[a-zA-z_]+')->where('item_id', '[a-zA-z-]+');
Last updated 1 year ago.
0

Nope you're not wrong! Try this:

Route::get('sale_add_item/{alias}/{item_id?}', function($alias, $item_id = null)
{
});
Last updated 1 year ago.
0

@feelinc : Same problem... If there are special characters in $alias for Redirect::to('sale_add_item/'.$alias), Laravel doesn't go in this route (Route::get('sale_add_item/{alias}/{item_id?})

Last updated 1 year ago.
0

AnthonyVipond said:

Nope you're not wrong! Try this:

Route::get('sale_add_item/{alias}/{item_id?}', function($alias, $item_id = null)
{
});

That's what i do, and it doesn't "catch" the Redirect::to() with special characters in $alias

Last updated 1 year ago.
0

You just need to find the correct Regex at :

where('alias', '[a-zA-z_]+')
Last updated 1 year ago.
0

What are the special characters? Many are not allowed in URLs, and it's always easier not to use them.

Mei

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

soclosed soclosed Joined 5 Feb 2014

Moderators

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

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.