Hello to all, welcome to therichpost.com. In this post, I will tell you, Php Artisan Tinker Database Commands which makes life easy.
I was working with laravel from last one year but I never used tinker in laravel and today I used it and I felt relax because with the help of laravel tinker, I can get database records easily and fast and these all the reasons which makes laravel better php mvc framework.
I will share some useful laravel tinker database commands with you guys.
Here are some Php Artisan Tinker Database Commands which makes life easy:
1. Very first, you need to run below command set tinker environment:
php artisan tinker
2. Here is the php artisan tinker database command to get all data records from particular table:
>>> DB::table('users')->get();
3. Here is the php artisan tinker database command to get limit of records from particular table:
>>> use App\User;
>>> User::limit(10)->get();
4. Here is the php artisan tinker database command to add new record in particular table:
>>> $user = new App\User;
>>> $user->name = "Hello laravel";
>>> $user->email = "hello@hellolaravel.com";
>>> $user->password = Hash::make('password');
>>> $user->save();
5. Here is the php artisan tinker database command to delete record in particular table:
>>> $user = App\User::find(28);
>>> $user->delete();
6. Here is the php artisan tinker database command to count total record in particular table:
>>> App\User::count();
7. Here is the php artisan tinker database command to create dummy record in particular table:
This is very helpful and save lots of time:
>>> factory(App\User::class,10)->create();
8. Here is the php artisan tinker database command to check database connection status:
>>> DB::connection()->getPdo();
9. Here is the php artisan tinker database command to check database name:
>>> DB::connection()->getDatabaseName();
10. Here is the php artisan tinker database command to check database tables names:
>>>DB::select('show tables');
11. Here is the php artisan tinker database command to delete particular table:
>>>DB::table('pages')->truncate();
12. Here is the php artisan tinker database command to generate hash dummy password:
>>> echo Hash::make("password");
If you have any query or you want more tinker commands then do comment below or ask question.
Thank you,
Save Birds,
TheRichPost
Recent Comments