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

Inside Mumbai’s Live Entertainment Scene: A Local’s Guide to Shows, Venues, and Smart Booking

Ask ten Mumbai residents how they spend a Friday night, and you will hear ten completely different answers. One friend might be queuing outside a sunlit theatre…

Read More

Step-by-Step Mumbai Transit and City Guide for Visitors and New Residents

Most people meet Mumbai through two extremes: either a breathless movie montage of Marine Drive at sunset, or a horror story about squeezing onto a crowded commuter…

Read More

Essential NoOps Automation Tools for Declarative Cloud Infrastructure

Spend a week inside a busy engineering organization and you will spot a familiar bottleneck. Talented developers write new features in hours, yet getting a test environment…

Read More

Engineering Operations Readiness: Evaluating Services Before and After Launch

Introduction Most engineering organizations do not lack tools. They lack an honest map — a clear understanding of where they stand, which capabilities are genuinely missing, and…

Read More

From Unboxing to Daily Mastery: A Simple iPhone and Mac Checklist

Introduction If you own an Apple device, you have probably asked at least one of these questions: Is my iPhone getting the new update? How do I…

Read More

NoOpsSchool Explained: Learning, Certification, and Automation Help in One Place

It is 9 p.m., and a system admin is fixing the same fault she fixed last week. A disk filled up. A service stopped. She runs the…

Read More