Easy Way To Add a User in Laravel

Laravel is one of the most popular PHP frameworks used for web development and API’s. In this article, I will show you how to add a new user in Laravel via Tinker with just one line of code.

Sometimes when you’re building a new project or debugging an existing one, you need a quick way to add a new user. Well, this is the code snippet you need to do just that using tinker. Keep it handy!

Using Tinker to Add a New User

You can do this by using the following command:

derek@codes $ php artisan tinker
Psy Shell v0.11.9 (PHP 8.1.13 — cli) by Justin Hileman
> User::create(["name" => "Derek Codes", "email" => "derek@random-email.com", "password" => bcrypt("!DerekCodes99")]);


Watch me walk through how to add a user in Laravel using tinker and more on my YouTube Channel:

Happy Coding!

~ Derek Codes

Share via
Copy link
Powered by Social Snap