2

I had this piece of route in a project in Laravel 3:

Route::get(array('/Home', '/'.rawurlencode ('خانه')), function()
{
    return View::make('home.index');
});

It was working correctly, till I decided to migrate it to Laravel 4. Now in Laravel 4 I get this error:

preg_match_all() expects parameter 2 to be string, array given

Are there any other way to set multiple patterns for Laravel 4 route?

2 Answers 2

4

You can achieve this using where with your route,

So if your route is,

Route::get('{home}', function()
{
    return View::make('home.index');
})->where('خانه', '(home)?');

You can access the same using,

http://localhost/laravel/home
http://localhost/laravel/خانه

Here the http://localhost/laravel/ should be replaced with yours.

Using regex is the best way,

Route::get('{home}', function()
{
    return View::make('home.index');
})->where('home', '(home|خانه)');

This will match only,

http://localhost/laravel/home
http://localhost/laravel/خانه
Sign up to request clarification or add additional context in comments.

Comments

0

You can use regex in the route so maybe something like this.

Route::get('(Home|' . rawurlencode('خانه') . ')', function ()
{
    return View::make('home.index');
});

If that doesn't work I'd probably just define two route's because the closure is so simple. Even if it is more complex, you could move it to a controller and point two routes at the same controller method.

1 Comment

Thanks buddy! Unfortunately it didn't work... But Devo's solution was great... :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.