我不应该将Laravel控制器用于非http请求

I'm designing a module, to take in a "notification request", render it, and deliver it over email or sms. After a few hacky revisions, I realized, that I'm basically doing a request, to a controller, passing parameters, and rendering a view.

I'm planning on doing something like

App\Sms\Controllers\UserController.php. In it I'll have getNewUser($user). I will capture the output of that, and pass it to my SMS API.

My question is, is there something negative I need to be aware of, by subclassing from Illuminate\Routing\Controller.php?

Some examples I can think of include having to hide/block these routes from being hit via http.

I will call the controller with something like

$request = Request::create('api/items', 'GET', $params);
return Route::dispatch($request)->getContent();

This is exactly what the Command Bus is for (Not to be confused with Artisan Commands). http://laravel.com/docs/5.0/bus

These allow you to fire a "Command" from anywhere within your application and process that accordingly.

There are two negative side effect for calling Route::dispatch directly.

First, is that you lose Route::getCurrentRoute(), so you cant find out which URL you are on. This was as big issue for me.

I ended up doing

$this->router = new Router(app('events'), app()); $request = Request::create($url, 'GET'); Input::initialize($event->toArray()); $out = $this->router->dispatch($request)->getContent();

That way, my getCurrentRoute was unaffected.

Second, the callstack gets deep - and you may hit the 100 xdebug limit - Increasing nesting function calls limit