CRUD USING QUIRY BUILDER IN LARAVEL.

We are performing crud opertion using quiry builder in laravel

STEP : 1

Create Laravel project by running this command in terminal

CMND :– Laravel new project_name

STEP : 2

Open xammp control panel and run apache and mysql server

STEP : 3

Ceate a new database through phpmyadmin

STEP : 4

Change the database name in .env file which we have to use

STEP : 5

Creating a migration model and controller file with resources using a single line command

CMND :– php artisan make:model MODEL_NAME -mcr

here -mcr means Migration , Controller , Resouces

STEP : 6

Now serve the file by running this command

CMND :– php artisan serve

STEP : 7

Creating the table

When we run resources file its give a set of function and blueprint of the progrmme

A migratiion file is created in the migration folder with name of the controller

in this migration file we have to perform all the crud function

here i write the code for the creating a table

CODE :–

public function up()
    {
        Schema::create('students', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('city');
            $table->bigInteger('marks');

            $table->timestamps();
        });
    } 

STEP : 8

After this step we have to migrate this file through this command

CMND :– php artisan migrate

STEP : 9

Now we insert the value in the tabel

CODE :–

  public function create(Request $request)
    {
        DB::table('students')->insert([
            'name'=>$request->name,
            'city'=>$request->city,
            'marks'=>$request->marks,
        ]);
        return redirect(route('index'))->with('status','student added ');
    }

before this we have use the path of bd

use Illuminate\Support\Facades\DB;

STEP :10

Update the value

  public function update(Request $request , $id)
    {
    DB::table('students')->where('id',$id)->update([   
    'name'=>$request->name,
    'city'=>$request->city,
    'marks'=>$request->marks,
]);
return redirect(route('index'))->with('status','student updated');

    }

STEP : 11

Edit the record

 public function edit($id)
    {
        $student=DB::table('students')->find($id);
        return view('editform',['students'=>$student]);
    }

STEP : 12

Deleting the record

public function destroy(Student $student)
    {
        DB::table('students')->where('id',$id)->delete();
    }

NOTE : – Its only the execution code not a whole entire programme only the code for crud is above

To make active the code we have to make the route for the controller and return something through view .

We also have to import controller class

We have to work on the frontend where we have to make some table name the tabel and store the detail in database through tabel

THANKU.

Related Posts

Blade in Laravel

Blade is the simple,yet powerful templating engine that is included with laravel. Blade does not restrict you from using plain php code in your templates. Blade templates…

Read More

Controller In Laravel

Controllers can group related request handling logic into a single class, Instead of defining all of your request handling logic as closure in route files ,you may…

Read More

LARAVEL ROUTING

All Laravel routes are define in route files , which are located in the route directory ,These file are automatically loaded by the framework. The most basic…

Read More

MVC (MODEL VIEW CONTROLLER)

MVC stands for Model–view–controller. The MVC is an architectural pattern model that seprates an applications into three logical components.(Model , View, Controller) MVC was first introduce in…

Read More

ReflectionException : Class BlogsTableSeeder does not exist

When i type php artisan db:seed command. It’s showing this type of errors. [ReflectionException]Class UserTableSeeder does not exist Here is my BlogsTableSeeder <?phpuse Illuminate\Database\Seeder;class BlogsTableSeeder extends Seeder{…

Read More

How to Creating a personal access token, Personal API tokens in Github | How to use GitHub personal access token

When i pushed code on GitHub its showing you don’t have Personal Access Token. When i try to push code on github its showing cURL method to…

Read More