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 Controller
s __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
even though 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.