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 

by using tinker command line we can create new user or insert new data in database


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,
  }
>>> 


or you can use different approaches to store new data let 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