Reset
Add Foreign Key Relationships to Business Relations
Program Info
Program Code
×

Add Foreign Key Relationships to Business Relations

This migration adds foreign key relationships for user_id and region_id in the business_relations table. It also allows region_id to be nullable and automatically updates or deletes related records when the parent record changes or is deleted. The down() method removes these foreign key constraints when the migration is rolled back.

Footer

×

Add Foreign Key Relationships to Business Relations

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('business_relations', function (Blueprint $table) {            
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
            $table->unsignedBigInteger('region_id')->nullable()->change();
            $table->foreign('region_id')->references('id')->on('states')->onDelete('cascade')->onUpdate('cascade');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('business_relations', function (Blueprint $table) {
            $table->dropForeign(['user_id']);
            $table->dropForeign(['region_id']);
        });
    }
};

Footer

Add Gender Column to Employee Table
Program Info
Program Code
×

Add Gender Column to Employee Table

This migration adds a new gender column to the employee table. The column accepts M, F, or O and can also be left empty.

Footer

×

Add Gender Column to Employee Table

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('employee', function (Blueprint $table) {
            $table->enum('gender',['M','F','O'])->nullable()->after('email');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('employee', function (Blueprint $table) {
            //
        });
    }
};

Footer

Add Soft Delete Support to Quotes Table
Program Info
Program Code
×

Add Soft Delete Support to Quotes Table

This migration adds soft delete support to the quotes table. Deleted quotes are not permanently removed from the database and can be restored later.

Footer

×

Add Soft Delete Support to Quotes Table

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('quotes', function (Blueprint $table) {
            $table->softDeletes();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('quotes', function (Blueprint $table) {
            //
        });
    }
};

Footer

Add Tab and Progress Tracking Fields to Pages Table
Program Info
Program Code
×

Add Tab and Progress Tracking Fields to Pages Table

This migration adds four fields to the pages table to save the current tab and progress for both users and admins. It also removes these fields if the migration is rolled back.

Footer

×

Add Tab and Progress Tracking Fields to Pages Table

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('pages', function (Blueprint $table) {
            $table->integer('current_tab')->default(0)->before('status');
            $table->integer('current_progress')->default(0)->after('current_tab');
            $table->integer('admin_current_tab')->default(1)->after('current_progress');
            $table->integer('admin_current_progress')->default(0)->after('admin_current_tab');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('pages', function (Blueprint $table) {
            $table->dropColumn('current_tab');
            $table->dropColumn('current_progress');
            $table->dropColumn('admin_current_tab');
            $table->dropColumn('admin_current_progress');
        });
    }
};

Footer

Add User Attempt Flag and Update Existing Users
Program Info
Program Code
×

Add User Attempt Flag and Update Existing Users

This migration adds a user_attempt column to the users table. It sets the value to 1 for existing users who have the user role, while new users get a default value of 0.

Footer

×

Add User Attempt Flag and Update Existing Users

<?php

use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->tinyInteger('user_attempt')->default(0)->nullable();
        });

        User::whereHas('roles',function($query) {
            $query->where('role_type','user');
        })->update(['user_attempt' => 1]);
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn('user_attempt');
        });
    }
};

Footer

Add User Contact, Image, and Region Details
Program Info
Program Code
×

Add User Contact, Image, and Region Details

This migration adds phone number, extension, user image, ZIP code, and region information to the users table. It also creates a relationship between region_id and the states table. The down() method removes these changes when the migration is rolled back.

Footer

×

Add User Contact, Image, and Region Details

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->string('phone_number')->after('status')->nullable();
            $table->string('extention')->after('phone')->nullable();
            $table->longText('user_image')->after('extention')->nullable();
            $table->unsignedBigInteger('region_id')->after('user_image')->index()->nullable();
            $table->string('zip_code')->after('region_id')->nullable();

            $table->foreign('region_id')->references('id')->on('states')->onUpdate('cascade')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropForeign(['region_id']);
        
            // Drop columns added in the up method
            $table->dropColumn([
                'phone_number',
                'extention',
                'user_image',
                'region_id',
                'zip_code'
            ]);
        });
    }
};

Footer

Calculate Average Employee ID
Program Info
Program Code
×

Calculate Average Employee ID

This query calculates the average value of the id column from the employee table.

Footer

×

Calculate Average Employee ID

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Query_Controller extends Controller
{
    public function index()
    {
        $data = DB::table('employee')->avg('id');
        echo "<pre>";
        print_r($data);
    }
}

Footer

Calculate the Sum of Employee IDs
Program Info
Program Code
×

Calculate the Sum of Employee IDs

This query adds all the id values from the employee table and returns the total sum.

Footer

×

Calculate the Sum of Employee IDs

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Query_Controller extends Controller
{
    public function index()
    {
        $data = DB::table('employee')->sum('id');
        echo "<pre>";
        print_r($data);
    }
}

Footer

Check if an Employee Record Exists
Program Info
Program Code
×

Check if an Employee Record Exists

This query checks whether an employee with ID 1 exists in the employee table. It displays "Data is Available" if the record exists and "Data is Not Available" if the record does not exist.

Footer

×

Check if an Employee Record Exists

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Query_Controller extends Controller
{
    public function index()
    {
        if(DB::table('employee')->where('id',1)->exists())
        {
            echo "Data is Available";
        }
		
        if(DB::table('employee')->where('id',1)->doesntExist())
        {
            echo "Data is Not Available";
        }
    }
}

Footer

Clear All Records from Contact Table
Program Info
Program Code
×

Clear All Records from Contact Table

This query deletes all records from the contact table and resets its auto-increment counter.

Footer

×

Clear All Records from Contact Table

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Query_Controller extends Controller
{
    public function index()
    {
        DB::table('contact')->truncate();     
    }
}

Footer

Showing page  1  of  8  (Total  77 records)
 1  2  3 ... 8  Next »
×
Name : Krishna Verma    |    Father's Name : Mr. Satish Kumar    |    Email ID : krishnaverma28081997@gmail.com    |    Religion : Hindu    |    Address : Dayampur, kanker khera, Meerut Cantt (250001), UP    |    Date of Birth : 28 August 1997    |    Marital Status : Non-Married    |    Place of Birth : Dayampur Kanker Khera Meerut Cantt.    |    Gender : Male    |    Age : 28    |    Contact : 9520335394    |    Father's Occupation : Sports man    |    Mother's Name : Smt. Kuntesh Devi    |    Mother's Occupation : Homemaker    |    Number of Brothers : 1    |    Number of Sisters : 1    |    Current Residence : Dayampur kanker khera meerut cantt    |    Family Type : Nuclear Family    |    Family Name : verma    |    Height : 5' 6"    |    Weight : 70 kg    |    Complexion : Fair    |    Body Type : Athletic    |    Hair Color : Black    |    Health Status : Good    |    Any Physical Disability : No    |    Highest Qualification : B.Tech (CSE)    |    Master Skill : PHP Laravel    |    Total Projects : 40 +    |    Total Skills : 25 +    |    Languages Known : Hindi and English    |    Website : krishnaportfolio.in    |    Siblings : 3    |    Nationality : Indian    |    Total Experience : 5 Years    |    LinkedIn : https://www.linkedin.com/in/krishna-verma-840b71356/    |    Total Programs : 10000    |    Total Projects : 40    |    Total Skills : 25    |    Total Experience : 5    |    Total DSA Problems : 200    |    Total Served Companies : 2    |    Leetcode : https://leetcode.com/u/krishnavermadeveloper/    |    Naukri : https://www.naukri.com/mnjuser/profile?id=&altresid