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 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"=>"larainfo@gmail.com","password"=>bcrypt("123456")]);
=> App\Models\User {#4290
name: "larainfo",
email: "larainfo@gmail.com",
updated_at: "2021-04-22 08:23:28",
created_at: "2021-04-22 08:23:28",
id: 1,
}
>>>
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= "larainfo@gmail.com";
=> "larainfo@gmail.com"
>>> $user->password=bcrypt('123456');
=> "$2y$10$uSdO/eBCQPNK3eVjXlSh.ulBVamZOhc.Hu5bp8Xzzb.uWyS3MSwRC"
>>> $user->save();
=> true
Top comments (0)