composer require lumite-studios/action
composer test
The \LumiteStudios\Action\Action
class can be used to simplify running various actions.
use LumiteStudios\Action\Action;
class CreateUser extends Action
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
return !auth()->check();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [
'email' => ['required', 'email'],
'password' => ['required'],
];
}
/**
* Handle the action.
*
* @param \Illuminate\Http\Request $request
* @return User
*/
public function handle(Request $request)
{
return User::create([
'email' => $request->email,
'password' => Hash::make($request->password),
]);
}
}