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

joedawson's avatar

Build up a Manual Request

Hello all,

I currently have an Entrymodel - of which when a user submits a form, the entire request object is passed to a custom method I have created that handles the creation or updating of an entry. Here's how it currently works.

public function store(EntryRequest $request)
{
    $entry = Entry::generate($request);

    // other stuff like flashing message and redirecting.
}

What I want to now do, is manually fetch a group of these entries (that already exist) - build up a request and run the same generate method I have set up.

So currently, what I've done is create a new console command - with when ran, will simply loop these entries and run the same generate method on them.

So my question is, is it possible to manually build up a request object?

I hope this makes sense!

Edit: This is what I currently have on my command.

public function handle()
{
    $entries = Entry::legacy()->processed()->get();

    foreach($entries as $entry)
    {
        // Create a request object here? Let's assume I assign this to a $request variable
        
        Entry::generate($request, $entry); // passing the created request and entry itself

        $this->info('Successfully converted entry #' . $entry->id);
    }
}
0 likes
3 replies
bashy's avatar
bashy
Best Answer
Level 65

What about

$request->merge([
    'field' => 'value',
]);

and add the request var via construct?

Are you trying to fake the form data to send it again?

joedawson's avatar

@bashy thanks buddy, think that'll work! The entries data already exists elsewhere, just need to create some kind of request to pass through to that generate method I have set up and it should work.

Thanks again!

public function handle()
{
    $entries = Entry::legacy()->processed()->get();

    foreach($entries as $entry)
    {
        $request = new FormRequest; // Illuminate\Foundation\Http\FormRequest

        $request->merge($entry->data); // think a lot will be going on here, but will extract it all to a custom method.
        
        Entry::generate($request, $entry); // passing the created request and entry itself

        $this->info('Successfully converted entry #' . $entry->id);
    }
}
bashy's avatar

Cool, yeah that's what I thought you wanted to do!

Please or to participate in this conversation.