I use this approach https://laracasts.com/series/whats-new-in-laravel-7/episodes/6 and it works really well. Surely you can 'steal' some ideas from there. I see no reason for reinventing the wheel, Laravel ships with pretty awesome authentication package!
Jun 5, 2020
7
Level 3
Using the default RegisterController to register from API
Is it recommended to re-user the default RegisterController to register from API or is it easier to create a new one ?
I tried to use the default one, but I didn't figure out how to pass name/login/password to the $data variable of the RegisterController.
Level 80
@devondahon Create a controller that creates a user. The register controller that comes with Laravel will try and log the user in; you don’t want that.
It’s not that complicated:
namespace App\Http\Controllers\Api;
use Illuminate\Auth\Events\Registered;
use Illuminate\Routing\Controller;
class UserController extends Controller
{
public function store(StoreUserRequest $request)
{
$user = User::create($request->validated());
event(new Registered($user));
return new UserResource($user);
}
}
1 like
Please or to participate in this conversation.