Reputation: 241
I'm building a php class which need for some methods a Request instance.
Example :
static public function warningAlert($message, Request $request) {
$request->session()->flash('alert-warning', "$message");
}
I thought that the service provider will provide this instance but he dont :
Argument 2 passed to ...\validatorAlerts() must be an instance of Illuminate\Http\Request, none given
How can I provide him ?
PS : I don't wan't to use facades.
Upvotes: 1
Views: 1072
Reputation: 1230
You can use the helper function request()
static public function warningAlert($message) {
request()->session()->flash('alert-warning', "$message");
}
Or even better, I do recommend you to use the laracasts/flash
package
Upvotes: 1
Reputation: 40653
You could do something like:
app()->call('Classname::warningAlert', [ $message ]);
Alternatively you can modify your method:
static public function warningAlert($message) {
$request = resolve("request");
$request->session()->flash('alert-warning', "$message");
}
Upvotes: 1