Is it better now?
User Controller after refactor
<?php
namespace App\Http\Controllers;
use App\Http\Requests\StoreUserRequest;
use App\Models\User;
class UserController extends Controller
{
public function store(StoreUserRequest $request)
{
$attributes = $request->validated();
User::create($attributes);
return response()->noContent();
}
}
Let's discuss new code
- not the best example to refactor
- mental footprint: keep everything inside controller vs multiple class approach
- easier to test
- we have options 👍