If you familiar with Jetstream, you will noticed app/Actions directory in your project. The usage should only need to extend the base class, define rules and model going to use. With 4 above rules: inputs = $inputs; return $this; } public function setConstrainedBy(array $constrainedBy): self { $this->constrainedBy = $constrainedBy; return $this; } public function getConstrainedBy(): array { return $this->constrainedBy; } public function hasConstrained(): bool { return count($this->getConstrainedBy()) > 0; } public function getInputs(): array { return $this->inputs; } public function model(): string { if (! property_exists($this, 'model')) { throw ActionException::missingModelProperty(__CLASS__); } return $this->model; } public function execute() { Validator::make( array_merge( $this->getConstrainedBy(), $this->getInputs()), $this->rules())->validate(); return $this->record = DB::transaction(function () { return $this->hasConstrained()?
The usage: use \App\Actions\User\UpdateOrCreate as UpdateOrCreateUser; $data = [ 'name' => 'Nasrul Hazim', 'email' => 'nasrul@somewhere.com', 'password' => 'password', 'password_confirmation' => 'password', ]; (new UpdateOrCreateUser($data))->execute(); Another example: ['required', 'string', 'max:255'], ]; }}