vendredi 14 juin 2019

Laravel change binding with Request params

I am using Laravel Framework 5.8.21. I am trying to bind an interface to a class based on Request params inside AppServiceProvider's register method like this.

public function register()
{
  $this->app->bind('App\Contracts\SomeInterface', 'App\Logic\ClassName');
  if(Request::has('notification_type') && Request::get('notification_type') == 'email') {
    $this->app->bind('App\Contracts\SomeInterface', 'App\Logic\SomeotherClassName');
  }
}

and later injecting the interface to Controllers __construct() method.

with tests, it always bound to ClassName. I tried to get accessed url inside AppServiceProvider and while running unit tests, it always returning / with $this->app->request->getRequestUri(); and method as GET eventhough from the test I am posting to url like this.

$this->post('/notification', [
            'notification_type' => 'email',
  ])->assertJson(   
     'message-push-status' => true,
  ]);

While testing it with Postman, when I try to post http://localhost:8000/notification, it says, 419 | Page Expired.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire