Laravel Tinker with PHP Artisan command to update user details

Laravel Tinker with PHP Artisan command to update user details

In this post we will give you information about Laravel Tinker with PHP Artisan command to update user details. Hear we will give you detail about Laravel Tinker with PHP Artisan command to update user detailsAnd how to use it also give you demo for it if it is necessary.

In this Laravel tutorial, I will tell you about the ‘Tinker’ one of the awesome features in Laravel application which allow user to interact with entire Laravel applications from the command line.

You can put all eloquent queries on command line with the help of tinker.

With the help of Laravel’s lesser-known features, You can quickly read data from the Database in Laravel application.

Laravel tinker is a repl (Read–Eval–Print Loop) powered by the PsySH package.

Before tinker, install the laravel application and the run the migration command to create table :

php artisan migrate

After running migration command, you will see the following output :

Now run artisan command to enter into tinker environment :

php artisan tinker


Seeding Database with Test Users

First, we will seed our database with 10 new user details by running following line of command :

factory(AppUser::class, 10)->create();

You can count the total number of users in the database by running following command :

AppUser::count();


Adding a New User

You can create a user from the repl. I have already told you that you can put your eloquent queries just like you write code in Laravel application :

  1. $user=new AppUser;
  2. $user->name ="Ajay";
  3. $user->email ="ajay.agrahari09@gmail.com";
  4. $user->password=bcrypt('123456');
  5. $user->save();
$user = new AppUser;
$user->name = "Ajay";
$user->email = "ajay.agrahari09@gmail.com";
$user->password=bcrypt('123456');
$user->save();


Output :


Update User Details

Run the query to update user details :

  1. $user= AppUser::find(2);
  2. $user->name='Test User';
  3. $user->save();
$user = AppUser::find(2);
$user->name='Test User';
$user->save();

Output :


Delete User

Run the following query to delete user from database :

  1. $user= AppUser::find(1);
  2. $user->delete();
$user = AppUser::find(1);
$user->delete();

Output :



This is a really awesome and useful tool.

Hope this code and post will helped you for implement Laravel Tinker with PHP Artisan command to update user details. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github