Categories

Thursday, November 21, 2024
#919814419350 therichposts@gmail.com
LaravelLaravl 5.7

Php Artisan Tinker Database Commands which makes life easy

Laravel 7.2 routing with route group auth guard check with prefix

Php Artisan Tinker Database Commands which makes life easy

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();

limit_of_records

 

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();

add_new_data_laravel

 

5.  Here is the php artisan tinker database command to delete record in particular table:
>>> $user = App\User::find(28);

>>> $user->delete();

delete_record_laravel

 

6.  Here is the php artisan tinker database command to count total record in particular table:
>>> App\User::count();

data_count_laravel

 

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();

dummy_data_laravel

 

8.  Here is the php artisan tinker database command to check database connection status:
>>> DB::connection()->getPdo();

check_database_laravel_tinker

 

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");  

shah_passpwrd_laravel

 

If you have any query or you want more tinker commands then do comment below or ask question.

Thank you,

Save Birds,

TheRichPost

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.