0

I need to get the static Route:: inside controller

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

class processController extends controller
{
    public function process()
    {
       Route::get('myroute', myController@method);
    { 

}

I have try to use: use Illuminate\Routing\Route; But this is not working.

7
  • This won't work. By the time your controllers are hit, the routes have already been registered and this won't be available either for the next request either. May 9, 2016 at 17:08
  • I don't care if Works, i wan't pass the static Route inside my controller just this. "SIMPLE" just this! May 9, 2016 at 17:11
  • 1
    Okay, all you should need is \Route::get('myroute', 'myController@method'); Keep in mind this is like asking how to buy tickets to a sporting event after the event has already finished so anything you try to do with this will just end up wasting your time. May 9, 2016 at 17:17
  • @user3158900, I've tried tell him it's a nonsense, but he doesn't want to hear that. ) May 9, 2016 at 17:20
  • Yes, ok! But i don't care if that have a sense! I wan't pass the Route::get(); inside from my controller! Please guys, let's communicate May 9, 2016 at 17:26

3 Answers 3

2

What you are trying to do will end up calling a controller method.

Rather than Using Route inside Controller call Controller Method directly. You can also call a controller method from another controller like this:

app('App\Http\Controllers\YourContoller')->methodName();

11
  • Wow this is very interest! This give me the same object with the Route? May 9, 2016 at 17:52
  • for example can say: app($myController)->resource($myRequestPage)->methodName($myMethod); I thing not! this can be don only with: Route::resource('myroute', myController@method); May 9, 2016 at 17:56
  • But i like that! Is very usefull May 9, 2016 at 18:00
  • 1
    Yes this is batter solution, app('App\Http\Controllers\myController')->method(); May 9, 2016 at 18:01
  • If that is solution of your question. You can accept it as answer May 9, 2016 at 18:03
1

If you want to send user to the route, you can do this:

redirect->route('myroute');

If you want to build a path to route, just use this:

$url = route('myroute');
11
  • I need to get the static Route:: inside controller May 9, 2016 at 16:42
  • Do you mean you want to create new route with controller method? May 9, 2016 at 16:43
  • I want use exactly the: Route::get('myroute', myController@method); from my controller May 9, 2016 at 16:45
  • Well, it's really unclear what are you asking. What exactly do you want? Can you describe it please. May 9, 2016 at 16:46
  • I want use exactly the: Route::get('myroute', myController@method); from my controller! Just this, i am very very clear :) you know how can do that? May 9, 2016 at 16:47
0

you can use;

 return redirect()->action('MyController@methodname');

to get redirected to a specific controller method

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.