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

jove's avatar
Level 7

Custom value in custom requests + Model::create

So I have not used Model::create(); a lot, I have used to use the new Model(); but it takes a lot of code and if I can just do it in Model::create(); I don't see the problem. Now my question is this.

I have a simple Agent model, it's a hasMany to User so it has a user_id field.

I think this would work nicely? StoreAgentRequest.php

public function validationData()
    {
        return $this->merge([
            'user_id' => auth()->user()->id
        ]);
    }

But how do I use the create now?

Agent::create($request->validated());

This only takes validated data right? and I don't want to do all here so that it get's feeded stuff it should not have.

What's the best Laravel way here?

0 likes
2 replies
jove's avatar
Level 7

Ah, awesome. Can't remember I have seen this.

Please or to participate in this conversation.