...

/

Welcome New Users Via an API

Welcome New Users Via an API

Get ready for the first API endpoint: Registration of users.

User model and migration

Out of the box, each new Laravel web app comes up with the model and migration files for the user’s module. The default columns are enough for this project, and we do not need to add or remove any columns.

Opening up the register URL

We can directly add a POST route to accept data to register a new user. This will be inside the routes/api.php file instead of the regular routes/web.php file.

Press + to interact
<?php
use App\Http\Controllers\RegisterController;
use Illuminate\Support\Facades\Route;
Route::post('/register', RegisterController::class);

Handle the requests with a Controller

You already know that the Controller takes charge when a particular route is called. In this course, we will be keeping our classes neat and clean by following some best practices. Here are some of the highlights before you see the actual code:

  • A method should preferably do just one
...