Skip to content

Instantly share code, notes, and snippets.

@greenspace10
Created March 21, 2022 08:39
Show Gist options
  • Save greenspace10/8cbac22e6d1d99eec19733c0cfd3234b to your computer and use it in GitHub Desktop.
Save greenspace10/8cbac22e6d1d99eec19733c0cfd3234b to your computer and use it in GitHub Desktop.
Multipart form actions
<?php
namespace App\Actions;
use App\Models\Branch;
use Lorisleiva\Actions\ActionRequest;
class CreateBranch
{
public function handle($data)
{
return Branch::create($data);
}
public function asController(ActionRequest $request)
{
$business = $this->handle($request->validated());
return redirect()->route('business.show', $business);
}
public static function make(ActionRequest $request)
{
return (new static)->handle($request->validated());
}
public function rules(): array
{
return [
'branch.name' => ['required', 'max:255'],
'branch.type' => ['required', 'max:100'],
'branch.address' => ['required', 'max:255'],
];
}
}
<?php
namespace App\Actions;
use App\Models\Business;
use Lorisleiva\Actions\ActionRequest;
class CreateBusiness
{
public function handle($data)
{
return Business::create($data);
}
public function asController(ActionRequest $request)
{
$business = $this->handle($request->validated());
$branch = CreateBranch::make($request);
return redirect()->route('business.show', $business);
}
public function rules(): array
{
return [
'business.name' => ['required', 'max:255'],
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment