Courses

Laravel Travel Agency API From Scratch

The next point in the client description is about creating users. In fact, it was the very first point in the original job description, but I decided to first work with showing the data and only then with managing it by users. So now it's time.


Task Description from Client

A private (admin) endpoint to create new users. If you want, this could also be an artisan command, as you like. It will mainly be used to generate users for this exercise.


Here's something illogical: if there is only an endpoint to create users, then who/how would create the very first admin user? :)

That's why I vote for the Artisan command from the very beginning, without any API endpoint. So this is precisely what we will do in this lesson.


Generating Artisan Command

This part is easy. We just need to run this in Terminal:

php artisan make:command CreateUserCommand

Notice: I personally like to suffix all Terminal commands with the word "Command" at the end.

We fill in the command signature and description. And then, we need to fill in the handle() method to create the user.

app/Console/Commands/CreateUserCommand.php:

namespace App\Console\Commands;
 
use Illuminate\Console\Command;
 
class CreateUserCommand extends Command
{
protected $signature = 'users:create';
 
protected $description = 'Creates a new user';
 
public function handle()
{
// TODO
}
}

The question is how to ask the Artisan Command user all the data about...

This lesson is only for Premium Members.
Want to access all lessons of this course?

You also get:

  • 66 courses (1167 lessons, 43 h 18 min total)
  • Premium tutorials
  • Access to repositories
  • Private Discord