Ad
Accessing A Request Parameter Already Declared In Constructor In LARAVEL
I want to access a Request parameter in my Listener. I found this solution (to declare it in the constructor) but it should be only initialized in handle method?
I want to access my request in the onNewUser
method
my code
public function __construct(Request $request)
{
$this->request=$request;
}
public function handle($event)
{
//
}
public function subscribe($events)
{
$events->listen(
'eloquent.creating: App\Models\User',
'App\Listeners\[email protected]'
);
}
public function onNewUser(User$user){
userService::userModification($user, 'creating',$this->request);
}
Ad
Answer
Have you set $request
as your class's property? Like so:
class Something {
public $request;
public function __construct(Request $request)
{
$this->request = $request;
}
public function onNewUser()
{
return $this->request; // That way, you can initialize it here
}
}
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad