1

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();
Sh1d0w
  • 9,340
  • 3
  • 24
  • 35
mrwaim
  • 1,841
  • 3
  • 20
  • 29

2 Answers2

0

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.

Wader
  • 9,427
  • 1
  • 34
  • 38
  • I'm using the command bus to trigger sending the SMS/email - but i still want to resolve the "subject" and the "message". – mrwaim May 28 '15 at 08:31
  • Not sure what you mean by that? Can't you just pass that information into the command from where you're dispatching it? – Wader May 28 '15 at 13:11
  • The part I'm focusing on is, from a route say /add-user-notification/userid, or /delete-user-notification/userid, getting the correct data for the command (in this case the user object), and getting the right view for the command, and then, sending the data over SMS or email. Should I (or what bad things happen when I) use route::dispatch(/add-user-notifcation) - or a direct $smsMessageStore->getMessage('add-user-notification'). I hope this helps clarify it – mrwaim May 29 '15 at 16:00
0

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

Community
  • 1
  • 1
mrwaim
  • 1,841
  • 3
  • 20
  • 29