3

I try to rewrite Symfony routes to Laravel routes. The problem is that some Symfony routes take defaults and go the same controller. Can I add some arguments to the Laravel routes to accomplish the same?

e.g. Symfony yaml

 path: /account/
    defaults:
        _controller: "legacy.controller.fallback:Somefunt"
        pag_act: "secret"
        m_act: "home"

 path: /account2/
        defaults:
            _controller: "legacy.controller.fallback:Somefunt"
            pag_act: "public"
            m_act: "home"

e.g. laravel

Route::any('/account', 'SomeSymfonyController@Somefunt');

As you can see: the defaults for these 2 Symfony routes are different (pag_act), can I pass this in Laravel too?

0

2 Answers 2

10
Route::any('/account', 'SomeSymfonyController@Somefunt')
      ->defaults('pag_act', 'secret');

Route::any('/account2', 'SomeSymfonyController@Somefunt')
      ->defaults('pag_act', 'public');

and in your SomeSymfonyController Somefunt method

public function Somefunt(Request $request)
{
    dd($request->route('pag_act')); // Returns 'secret' or 'public' based on route
}
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, will test this and is probably exactly what I needed!
1

Simply create another Route::

Route::any('/account', 'SomeSymfonyController@secretFunt');
Route::any('/account2', 'SomeSymfonyController@publicFunt');

In your SomeSymfonyController you could say this:

public function secretFunt()
{
    $pag_act = 'secret';
    $m_act = 'home';
}

public function publicFunt()
{
    $pag_act = 'public';
    $m_act = 'home';
}

In case secretFunt() does the same as publicFunt(), but only the $pag_act's value is different: we don't want duplicate content whenever we process this $pag_act variable. So we can create a function for that:

public function funtHandler($act)
{
    $pag_act = $act;
    $m_act = 'home';
}

public function secretFunt()
{
    $pag_act = 'secret';
    $this->funtHandler($pag_act);
}

public function publicFunt()
{
    $pag_act = 'public';
    $this->funtHandler($pag_act);
}

1 Comment

Yes, the problem lies with wanting to use the same function in the controller., but this will work. Why? Because it's still shared with symfony.

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.