Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Mindexperiment's avatar

FormRequest inside a package?

Hi all,

I'm using a form request inside a package but nothing happen. No error, warning, nothing.. If I switch back to normal Request everything ok.

controller:

    // this won't work
    public function subscribe(SubscribeNewsletter $request)
    {

    // this work
    public function subscribe(Request $request)
    {

any help?

Thank you

0 likes
4 replies
hamiha's avatar

Whats the result when you post a request? Is it redirecting you back to the form page?

Tray2's avatar

In the top one you tell php that the parameter $request must be an instance of SubscribeNewsletter and in the second one it must be an instance of Request. You need to use the instance your code expects.

Mindexperiment's avatar

Hi,

all dependencies are correct, I checked 100 times =)

I suppose that should be a problem on the bindings:

I try

use Pkg\Newsletter\Http\Requests\SubscribeNewsletter;

class PkgServiceProvider extends ServiceProvider
{

    public function register()
    {
        $this->registerBindings();
    }

    /**
     * Register service container bindings
     * 
     * @return void
     */
    protected function registerBindings()
    {
        $this->app->singleton(SubscribeNewsletter::class, function ($app) {
            return new SubscribeNewsletter();
        });
    }

}

then composer dump-autoload but still no response.

@hamiha the page result is the same page I launch the request, the request is correctly sent but with SubscribeNewsletter I get nothing.. nothing at all..

@tray2 dependencies are correctly set, using standard Request the process goes well, when I switch to SubscribeNewsletter nothing.. I'm not sure I'm using dependency injection correctly

hamiha's avatar

There may be error messages, but you're not displaying them on the form page?

@foreach ($errors->all() as $error)
    <li>{{ $error }}</li>
@endforeach

Please or to participate in this conversation.