DEV Community

Cover image for How to Create a User using Tinker in Laravel
saim
saim

Posted on • Originally published at larainfo.com

How to Create a User using Tinker in Laravel

Tinker allows you to interact with your entire Laravel application on the command line, including the Eloquent ORM, jobs, events, and more. To enter the Tinker environment, run the tinker Artisan command.

php artisan tinker or php artisan ti 
Enter fullscreen mode Exit fullscreen mode

By using the tinker command line, we can create a new user or insert new data into the database.

Now run php artisan ti

Psy Shell v0.10.6 (PHP 7.4.16  cli) by Justin Hileman
>>> User::create(["name"=> "larainfo","email"=>"[email protected]","password"=>bcrypt("123456")]);
=> App\Models\User {#4290
   name: "larainfo",
   email: "[email protected]",
   updated_at: "2021-04-22 08:23:28",
   created_at: "2021-04-22 08:23:28",
   id: 1,
  }
>>> 
Enter fullscreen mode Exit fullscreen mode

Or you can explore different approaches to storing new data. Let's see.
php artisan ti

>>> $user = new App\Models\User;
=> App\Models\User {#4301}
>>> $user->name = "larainfo";
=> "larainfo"
>>> $user->email= "[email protected]";
=> "[email protected]"
>>> $user->password=bcrypt('123456');
=> "$2y$10$uSdO/eBCQPNK3eVjXlSh.ulBVamZOhc.Hu5bp8Xzzb.uWyS3MSwRC"
>>> $user->save();
=> true
Enter fullscreen mode Exit fullscreen mode

Top comments (0)