What is Tinker? How to Insert Data using Tinker?

In this tutorial i’m going What is tinker and why using it and how to insert data using of tinker in easy way. I’m going to describe each of every thing from sctatch so please follow these tutorials.

What is Tinker?

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.

First let’s go to install laravel project

composer create-project --prefer-dist laravel/laravel tinker"5.8.*"

After Installation setup database So go to the .env file and add the database credentials. lets go to .env folder and put database name and connect to database.

DB_CONNECTION=mysqlDB_HOST=127.0.0.1DB_PORT=3306DB_DATABASE=crud-operationDB_USERNAME=rootDB_PASSWORD=

Now Create Post table

php artisan make:migration create_posts_table --table=posts

Next go to your create_posts_table and add below column

$table->bigIncrements('id');$table->integer('user_id')->unsigned();$table->string('title');$table->text('content');$table->timestamps();

Now migrate the table.

php artisan migrate

Next go to your terminal and run below command.

php artisan tinker

Just paste below code as define.

$post = App\Post::create(['title'=>'php post tinker','content'=>'php content store tinker']);

Thanks i hope it’s helpfull for you 👍👍

Related Posts

A Fresh Way to Explore Bhopal Events, Attractions, and Local Experiences

Uncovering the authentic spirit of the City of Lakes goes well beyond visiting historical monuments and snapping photos of scenic waters. The true essence of Bhopal thrives…

Read More

Understanding Common Spinal Conditions and Researching Specialized Care Facilities

Introduction Finding the right hospital for a spine problem is not always as simple as searching for the best spine hospitals and choosing the first result. Patients…

Read More

Launching Your Aviation Career: How to Select the Right Flight School

Entering the aviation sector is an extraordinary milestone for anyone who has ever looked upward and envisioned a life in the cockpit. Whether your ambition is to…

Read More

The Definitive Handbook on Selecting Orthopedic Hospitals and Practitioners

Deciding where to seek treatment for an aching joint, an old sports injury, or persistent back pain is a pivotal moment in personal healthcare. Musculoskeletal concerns span…

Read More

Finding Reliable Legal Representation and Professional Guidance Online

Navigating personal or professional life often brings moments where legal clarity becomes essential. Whether someone is finalizing a real estate acquisition, managing a boundary disagreement, navigating marital…

Read More

Ask a Doctor Online: A Simple Guide to Virtual Healthcare

In our fast-paced world, the traditional trip to a doctor’s office isn’t always the most practical first step when health concerns arise. Whether you are dealing with…

Read More