Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Tinker Command and How to Insert Data in Database using Tinker in Laravel.

Tinker Command(php artisan tinker) is used to interact directly with the database table to insert, delete, update data. It executes SQL commands through the command line.

When we run the tinker command, it will open a shell where we can execute php commands. See below:-

How to use tinker in our project.

To use tinker, we have to make a migration in which we define a table and also defines the column. Make migration by using php artisan make:migration Name –create=Table_name command and define columns as I defined. See the below image:-

In the above example, I defined 4 columns of Name, E-mail, Location, and created_at, and also defined default values because if we can’t provide the value of any column then it assigns the default value in the database rather than giving error.

If we can’t provide a default value and adding the value of one column then, it gives an error that “This field is required” so we define a default value in each column to overcome from this type of error.

How to Insert Data in Database using Tinker.

To insert data in database table we use below PHP command. See below:-

Syntax

DB::table(“Table_Name”)->insert([“Column1″=>”Column1_data”, “Column2″=>”Column2_data”, “Column3″=>”Column3_data”);

For Example:- My table name is tinker and i’m inserting Name, E-mail, Location, and time indication created_at as mentioned above. See the below image what happened when i executed the command.

Let’s See in Database, my data added or not.

What happens when we insert value only for one column.

When we insert a value in only one column then, other columns filled by default value as I said above. See the below image for help:-

Let’s see in the Database, Other columns are filled with a Default value or not.

How to insert multiple Row’s in Database(Multiple rows Insertion).

To insert multiple rows in the database we use below syntax:-

See the below Program to understands better:-

Now, let’s see the database that our data was inserted or not.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
With MotoShare.in, you can book a bike instantly, enjoy doorstep delivery, and ride without worries. Perfect for travelers, professionals, and adventure enthusiasts looking for a seamless mobility solution.

Related Posts

What is Laravel and use cases of Laravel?

What is Laravel? Laravel is an open-source, free PHP web framework designed for the development of web applications following the model-view-controller (MVC) architectural pattern. It was generated…

Read More

Complete guide of Laravel certification courses, tutorials & training

What is Laravel Laravel is a reliable and simple to use open-source PHP framework. It adheres to the model-view-controller pattern of design. Laravel makes use of pre-existing…

Read More

Top 100 laravel interview questions and answers

1) What is Laravel? Laravel is an open-source widely used PHP framework. The platform was intended for the development of web application by using MVC architectural pattern….

Read More

[SOLVED] Laravel : Supervisor FATAL/BACKOFF Exited too quickly (process log may have details)

Problem I’m trying to use Laravel queues with a supervisor but the service is not working properly. When I try to check status:$ sudo supervisorctl status$ laravel-worker:laravel-worker_00:…

Read More

How to Login with Token in Laravel PHP Framework?

How to Login with Token in Laravel PHP Framework? Step 1. Create a new Project, so write down the following command on Git Bash: Step 2. Move…

Read More

Directory Structure Of Laravel Application

devopsschool – This is Project Folder app – The app directory contains the core code of your application. bootstrap – The bootstrap directory contains the app.php file…

Read More