Topic: Mysql

Search Filter using Nodejs and MySQL 0

Search Filter using Nodejs and MySQL

Search Filter using Nodejs and MySQL

In this Post We Will Explain About is Search Filter using Nodejs and MySQL With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Ajax Search Box using Node and MySQL Example

In this post we will show you Best way to implement Ajax Search box using Nodejs and MySQL, hear for Search record with two fields from MYSQL table by using Node.js with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Ajax Search box using Nodejs and MySQL

we prepare a simple connection by using mysql.createConnection() method of database connect MySQL simple module.There are simple very some things that we have to data define inside our create db connection data methods like localhost host name, simple user name, set your password, and set your database name.

Database details: connect with Node.js

  • set Hostname: localhost
  • database Port number: Set 3306
  • set Username: root
  • set Password: Pakainfo.com
  • simple set Database: Live24u
  • Set Table name: users
  • Fields: user_id and name
  • Server File : Node.js

    step-1 : prepare a connection

    var mysql = require('mysql');
    

    step-2 : Database Connect MYSQL table by using Node.js

    var DB_Conn = mysql.createConnection({
      host: "localhost",
      user: "root",
      password: "[email protected]#fdfjdf",
      database: "Live24u"
    });
    

    step-3 : query() method

    DB_Conn.connect(function(db_error) {
      if (db_error) throw db_error;
      console.log("Connected!");
      var sql = "select * from users where user_id='1' and name='jaydeep'";
    

    step-4 : query() method

    DB_Conn.connect(function(db_error) {
      if (db_error) throw db_error;
      console.log("Connected!");
      var sql = "select * from users where user_id='1' and name='jaydeep'";
    //step-4
      DB_Conn.query(sql, function (db_error, result) {
        if (db_error) throw db_error;
        console.log(result);
      });
    });
    

    Discussing steps that we have followed in our server file:

    1.Require simple MySQL module.
    2.Make Connection some variable using mysql.createConnection() function.
    3.Connect by using con.connect() function.
    4.make a SELECT Simple SQL some query by using data fields set user_id and name.
    5.Execute some query string by using .query() function.
    6.Show data result.

    Connecting nodejs app to Mysql

    You are Most welcome in my you tube Channel Please subscribe my channel. and give me Feed Back.
    More Details……
    Angularjs Example

    Example

    I hope you have Got What is nodejs ajax search bar with javascript ,juquery and mysql database And how it works.I would Like to have Feed Back From My Blog(Pakainfo.com) readers.Your Valuable Feed Back,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.

    PHP How-to create Dynamic PDF Files using FPDF 0

    PHP How-to create Dynamic PDF Files using FPDF

    PHP How-to create Dynamic PDF Files using FPDF

    In this Post We Will Explain About is PHP How-to create Dynamic PDF Files using FPDF With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Generating PDF files with PHP and FPDF Example

    In this post we will show you Best way to implement How-to create PDF documents using PHP, hear for Generate PDF from MySQL Data using FPDF with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

    PHP Script to create PDF document using FPDF

    First of all simple, you need to download FPDF libs. Download FPDF from here FPDF Download

    http://www.fpdf.org
    

    and then Keep the include the fpdf.php file in your root working directory,and then keep the font simple directory in the same root place.

    After that Run this source code ,and then you are know or ready with your simple first pdf file created from simple external FPDF class. Example of How to create PDF with PHP

    AddPage();
    $mypdf->SetFont('Arial','B',18);
    $mypdf->Cell(80,10,'Hello World!',1,0,R,true,'http://www.Pakainfo.com');
    $mypdf->Output('live_myfile.pdf','D'); // here Force download using FPDF to user machine as live_myfile.pdf
    ?>
    

    In the above simple source code we have used simple descign cell to add our new create text to the FPDF to pdf file. We have simple just added one text line Like as a ‘Wel-come to Pakainfo.com’ as well as simple created the pdfdouments file. Here more example is the simple details of Cell. Try to change the simple source code script by adding backgroud css color like this.

    $mypdf->SetFillColor(193,229,252);
    $mypdf->Cell(80,10,'Wel-come to Pakainfo.com',1,0,R,true,'http://www.Pakainfo.com');
    $mypdf->Output('live_myfile.pdf','D'); 
    

    We used to simple $mypdf->Output(‘my_file’,’D’) to get some here output simple directly. This line will force download to user machine the pdf file my_file.pdf. We can some data change this to serever side save the data file in local simple data PHP ( server ) side machine.

    $mypdf->Output('live_myfile.pdf','F'); // devloped by live24u Saved at local ( server side )  as live_myfile.pdf
    //$mypdf->Output('live_myfile.pdf','I'); //devloped by live24u Send to browser and simple displayed wiht the plugin, data file can be simple saved using  data set file name. 
    //$mypdf->Output('live_myfile.pdf','S'); //devloped by live24u Output as sting , here simple php file name is ignored.  
    

    You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
    More Details……
    Angularjs Example

    Example

    I hope you have Got What is How to create a dynamic PDF using PHP And how it works.I would Like to have FeedBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.

    Laravel Nested Relationships in Eloquent Example 0

    Laravel Nested Relationships in Eloquent Example

    Today, We want to share with you Laravel Nested Relationships in Eloquent Example.In this post we will show you Laravel Deeply nested relationships, hear for Get a nested relationship in Laravel we will give you demo and example for implement.In this post, we will learn about Eloquent nested relations with where clause with an example.

    Laravel Nested Relationships in Eloquent Example

    There are the Following The simple About Laravel Nested Relationships in Eloquent Example Full Information With Example and source code.

    As I will cover this Post with live Working example to develop Retrieving nested relationships using Laravel, so the Nested relationships when parent is a many-to-many relationship for this example is following below.

    Laravel Eloquent Relationships Tutorial Example From Scratch

    This is the Laravel Simple SQL Relationships query that works!

    SELECT member.id, 
           member.firstname, 
           member.lastname, 
           team_scores.score 
    FROM   teams 
           JOIN countries 
             ON countries.id = teams.country_id 
           JOIN vanues 
             ON countries.id = vanues.country_id 
           JOIN member 
             ON vanues.id = member.vanue_id 
           JOIN team_scores 
             ON team_scores.member_id = member.id 
    WHERE  team_scores.team_id = 1 
    GROUP  BY member.id 
    

    These are my Eloquent relations

    Team Model

    class Team extends Eloquent
    {
        protected $table = 'teams';
    
        public function country()
        {
            return $this->belongsTo('Country');
        }
    }
    

    Country Model

    class Country extends Eloquent
    {
        protected $table = 'countries';
    
        public function vanues()
        {
            return $this->hasMany('Vanue');
        }
    
        public function team()
        {
            return $this->hasMany('Team');
        }
    }
    

    Vanue Model

    class Vanue extends Eloquent {
    
        protected $table = 'vanues';
    
        public function member()
        {
            return $this->hasMany('Member');
        }
    
        public function country()
        {
            return $this->belongsTo('Country');
        }
    }
    

    Member Model

    class Member extends Eloquent
    {
        protected $table = 'member';
    
        public function vanue()
        {
            return $this->belongsTo('Vanue');
        }
    
        public function teamscore()
        {
            return $this->belongsToMany('Team', 'team_scores', 'member_id', 'team_id')
                ->withPivot('score')
                ->withTimestamps();
        }
    }
    

    PHP Laravel nested relationships Get Data

    return Team::with('country.vanues.member')->get();
    

    If you only want to select simple all the fields from the member table, use this:

    return Team::with(['country.vanues.member' => function ($query) {
        $query->select('id', '...');
    }])->get();
    

    Angular 6 CRUD Operations Application Tutorials

    Read :

    Summary

    You can also read about AngularJS, ASP.NET, VueJs, PHP.

    I hope you get an idea about Laravel Nested Relationships in Eloquent Example.
    I would like to have feedback on my Pakainfo.com blog.
    Your valuable feedback, question, or comments about this article are always welcome.
    If you enjoyed and liked this post, don’t forget to share.

    laravel search multiple tables Example 0

    laravel search multiple tables Example

    Today, We want to share with you laravel search multiple tables Example.In this post we will show you laravel select from multiple tables, hear for get data from multiple tables in laravel 5.7 we will give you demo and example for implement.In this post, we will learn about fetch data from two tables in laravel 5.7 eloquent with an example.

    laravel search multiple tables Example

    There are the Following The simple About laravel search multiple tables Example Full Information With Example and source code.

    As I will cover this Post with live Working example to develop Laravel 5.7 eloquent search multiple tables, so the some laravel search join tables for this example is following below.

    Searching multiple tables with one query with Laravel

    The Sample data is stored in tables as such:

    Teachers Categories
    teacherid_ studentid_
    teacher_name student_name
    teacher_student * student_slug

    The Laravel Problem

    Here’s some Laravel basic Relationship context to the issue. We have two models (‘Teacher’, and ‘Student’). They are joined Laravel Queries on a one-to-many relationship:

    app/models/Teacher.php

    class Teacher {
      ...
    
      public function student() {
        return $this->belongsTo('Student', 'teacher_student');
      }
    }
    

    app/models/Student.php

    class Student {
      ...
    
      public function Teacher() {
        return $this->hasMany('Teacher', 'student_id');
      }
    }
    

    Laravel 5.7 Search multiple tables for a search term

    $teachers = Teacher::whereHas('student', function($query) use($term) {
        $query->where('student_name', 'like', '%'.$term.'%');
    })->orWhere('teacher_name','LIKE','%'.$term.'%')->orderBy($order, 'asc')->get();
    

    we search for all teachers that have a related student.This is using the ‘student()’ function that defined earlier in the Teacher Model.

    Teacher::whereHas('student', function($query) use($term) {
        $query->where('student_name', 'like', '%'.$term.'%');
    })
    

    If this MySQL query returns no results, after that we fall back to the simple Call the second mysql query, where we query the teacher directly, here some data checking if the teacher name is like the search query

    ->orWhere('teacher_name','LIKE','%'.$term.'%')->get();
    

    Angular 6 CRUD Operations Application Tutorials

    Read :

    Summary

    You can also read about AngularJS, ASP.NET, VueJs, PHP.

    I hope you get an idea about laravel search multiple tables Example.
    I would like to have feedback on my Pakainfo.com blog.
    Your valuable feedback, question, or comments about this article are always welcome.
    If you enjoyed and liked this post, don’t forget to share.

    Get last inserted ID laravel 5.7 Examples 0

    Get last inserted ID laravel 5.7 Examples

    Today, We want to share with you Get last inserted ID laravel 5.7 Examples.In this post we will show you laravel 5.7 get insert id from eloquent model, hear for Get the Last Inserted Id Using Laravel Eloquent we will give you demo and example for implement.In this post, we will learn about Laravel 5.7 – Get last inserted id using save(), create() and insertGetId() with an example.

    Get last inserted ID laravel 5.7 Examples

    There are the Following The simple About MySQL last inserted ID laravel 5.7 Examples Full Information With Example and source code.

    As I will cover this Post with live Working example to develop Laravel 5.7 Ways to Get Last Inserted Id, so the GET LAST INSERTED ROW ID IN LARAVEL for this example is following below.

    Laravel’s Query builder

    working with Laravel DB::table()

    public function getLastInsertedIdDB()
    {
        $id = DB::table('products')->insertGetId(['product_name'=>'mobile']);
        print_r($id);
    }
    

    Laravel’s Eloquent ORM

    using laravel Model

    in this example use in laravel eloquent create last insert id

    public function getLastInsertedIdModel()
    {
        $create_product = Product::create(['product_name'=>'mobile']);
        print_r($create_product->id);
    }
    

    So in this tiny Post We will give you Good 3 example for getting last insert id in Laravel 5.7:

    • 1) save()
    • 2) create()
    • 3) insertGetId()

    Laravel 5.7 – Get last inserted id using save() Methods

    Example 1: Using Laravel 5.7 save() method

    public function craeteNewProduct(){
      $product_data =new Product();
      $product_data->name = "Mobile";
      $product_data->email = "[email protected]";
      $product_data->save();
      return $user->id;
    }
    

    Laravel 5.7 – Get last inserted id using create() Methods

    Example 2: Using Laravel create() method

    public function craeteNewProduct()
    {
        $id = DB::table('products')
                ->insertGetId(
                    ['name' => 'Mobile', 'email'=>'[email protected]']
                );
        return $id;
    }
    

    Laravel 5.7 – Get last inserted id using insertGetId() Methods

    Example 3: Using Laravel insertGetId() method

    public function craeteNewProduct()
    {
        $input = ['name' => 'MobileShop', 'email'=>'[email protected]'];
        $product = Product::create($input);
        return $product->id;
    }
    

    Laravel 5.7 Insert, Update, Delete

    Laravel Saving A New Model

    $product = new Product;
    $product->name = 'mobile';
    $product->save();
    
    $insertedId = $product->id;
    dd($insertedId);
    

    Laravel Updating A Retrieved Model

    $product = Product::find(1);
    $product->email = '[email protected]';
    $product->save();
    

    Deleting An Existing Model in Laravel

    $product = Product::find(1);
    $product->delete();
    

    Angular 6 CRUD Operations Application Tutorials

    Read :

    Summary

    You can also read about AngularJS, ASP.NET, VueJs, PHP.

    I hope you get an idea about Get last inserted ID laravel.
    I would like to have feedback on my Pakainfo.com blog.
    Your valuable feedback, question, or comments about this article are always welcome.
    If you enjoyed and liked this post, don’t forget to share.

    Laravel MySQL Database Relationship Queries 0

    Laravel MySQL Database Relationship Queries

    Today, We want to share with you Laravel MySQL Database Relationship Queries.In this post we will show you Creating Quick MySQL Relational Database, hear for Laravel MySQL Eloquent Relationships Tutorial Example From Scratch we will give you demo and example for implement.In this post, we will learn about Eloquent Laravel MySQL Relationships with an example.

    Laravel MySQL Database Relationship Queries

    There are the Following The simple About Laravel MySQL Database Relationship Queries Full Information With Example and source code.

    As I will cover this Post with live Working example to develop Speed up relationship queries in Laravel, so the Laravel nested relationships for this example is following below.

    Laravel Types of relationship in database with example

    List Types of relationships supported by Laravel

    There are Laravel support 7 types of table relationships

    • One To One
    • One To Many
    • One To Many (Inverse)
    • Many To Many
    • Has Many Through
    • Polymorphic Relations
    • Many To Many Polymorphic Relations

    Creating indexes in Laravel

    Adding indexes to your tables in Laravel is very straightforward. In your migrations you can add:

    //Laravel Single index
    $table->index('video_id');
    
    //Laravel Compound index
    $table->index(['notification_type', 'notification_id']);
    

    One to one / one to many relationships

    Simple Eloquent Laravel One to One Relationship

    $table->unsignedInteger('product_id');
    $table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');;
    
    $table->index('product_id');
    

    Many to many relationships

    One to Many Relationship in Laravel 5.7 Eloquent

    // products table
    $table->increments('id');
    
    // cats table
    $table->increments('id');
    
    // cat_product pivot table
    $table->unsignedInteger('product_id');
    $table->unsignedInteger('cat_id');
    

    we can add two to our pivot table

    // cat_product pivot table
    $table->unsignedInteger('product_id');
    $table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
    $table->unsignedInteger('cat_id');
    $table->foreign('cat_id')->references('id')->on('cats')->onDelete('cascade');
    

    Laravel duplicate can never exist in your database

    $table->unique(['product_id', 'cat_id']);
    

    Polymorphic / many to many polymorphic relationships

    // videos table
    $table->increments('id');
    
    // articles table
    $table->increments('id');
    
    // messages table
    $table->increments('id');
    $table->text('message_body');
    $table->text('notification_type');
    $table->unsignedInteger('notification_id');
    
    // messages table
    $table->index(['notification_id', 'notification_type']);
    

    Angular 6 CRUD Operations Application Tutorials

    Read :

    Summary

    You can also read about AngularJS, ASP.NET, VueJs, PHP.

    I hope you get an idea about Laravel MySQL Database Relationship Queries.
    I would like to have feedback on my Pakainfo.com blog.
    Your valuable feedback, question, or comments about this article are always welcome.
    If you enjoyed and liked this post, don’t forget to share.

    Print Debugging Queries in Laravel Example 0

    Print Debugging Queries in Laravel Example

    Today, We want to share with you Print Debugging Queries in Laravel Example.In this post we will show you Display all SQL executed in Eloquent, hear for How to get last executed query in Larave 5? we will give you demo and example for implement.In this post, we will learn about How to print query or debug queries in Laravel with an example.

    Print Debugging Queries in Laravel Example

    There are the Following The simple About Print Debugging Queries in Laravel Example Full Information With Example and source code.

    As I will cover this Post with live Working example to develop Debugging Queries in Laravel, so the Using toSql Function to Print SQL Query in Laravel for this example is following below.

    Laravel Debugging Queries with Example

    How to print query or debug queries in Laravel

    $results = Member::where(function($q) use ($request) {
        $q->orWhere('email', 'like', '%[email protected]%');
        $q->orWhere('member_fname', 'like', '%jaydeep%');
        $q->orWhere('member_lname', 'like', '%Gondaliya%');
    })->toSql();
    dd($results);
    

    How to get last executed query in Larave 5?

    \DB::listen(function($sql, $bindings, $time) {
    	//SQL query
        var_dump($sql);
        var_dump($bindings);
        var_dump($time);
    });
    

    Debugging Queries in Laravel

    $results = Member::where(function($q) use ($request) {
        $q->where('email', 'like', '%[email protected]%');
        $q->where('member_fname', 'like', '%jaydeep%');
        $q->where('member_lname', 'like', '%Gondaliya%');
    })->get();
    dd($results);
    

    How to get last executed query in Larave 5?

    Example 1: laravel tosql with parameters

    DB::enableQueryLog();
    $member = Member::get();
    $sql_qry = DB::getQueryLog();
    $sql_qry = end($sql_qry);
    print_r($sql_qry);
    

    Example 2: laravel tosql with parameters

    DB::enableQueryLog();
    $member = Member::get();
    $sql_qry = DB::getQueryLog();
    print_r($sql_qry);
    

    Example 3: laravel 5.4 get last query

    $member = Member::where('id',1)->toSql();
    print_r($member);
    

    Angular 6 CRUD Operations Application Tutorials

    Read :

    Summary

    You can also read about AngularJS, ASP.NET, VueJs, PHP.

    I hope you get an idea about Print Debugging Queries in Laravel Example.
    I would like to have feedback on my Pakainfo.com blog.
    Your valuable feedback, question, or comments about this article are always welcome.
    If you enjoyed and liked this post, don’t forget to share.

    How to Insert Data in Database using PHP OOPS 0

    How to Insert Data in Database using PHP OOPS

    How to Insert Data in Database using PHP OOPS

    In this Post We Will Explain About is How to Insert Data in Database using PHP OOPS With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to how to fetch data from database in php using oops Example

    In this post we will show you Best way to implement php mysql insert operation in PHP using OOP, hear for insert data in mysql using php class with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

    Setp 1.First create a html form

    Index.php

    	<form name="insert" action="" method="post">
           <table width="100%" border="0">
      <tr>
        <th width="26%" height="50" scope="row users">USER Full Name :</th>
        <td width="74%"></td>
      </tr>
      <tr>
        <th height="50" scope="row users">USER Email :</th>
        <td></td>
      </tr>
      <tr>
        <th height="50" scope="row users">USER Contact no. :</th>
        <td></td>
      </tr>
      <tr>
        <th height="50" scope="row users">USER Gender :</th>
        <td> Male   
    	 Female</td>
      </tr>
       <tr>
        <th height="50" scope="row users">USER Education :</th>
        <td>
    	Select Any one
    	10th
    	12th
    	Graduate
    	Post Graduate
    	 </td>
      </tr>
      <tr>
        <th height="50" scope="row users">USER Address :</th>
        <td><textarea name="user_address" class="form-control">
    	</textarea></td>
      </tr>
      <tr>
        <th height="50" scope="row users"> </th>
        <td></td>
      </tr>
    </table>
     
         </form>
    

    Setp 2. Create a database with name demos

    Inside demos content data base make a table inserdata
    Sample some Structure of user_mst table

    CREATE TABLE IF NOT EXISTS `user_mst` (
    `id` int(11) NOT NULL,
    `name` varchar(255) NOT NULL,
    `email` varchar(255) NOT NULL,
    `phone` bigint(20) NOT NULL,
    `user_gender` varchar(255) NOT NULL,
    `user_edu` varchar(255) NOT NULL,
    `user_user_address` longtext NOT NULL,
    `posting_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
    ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
    

    Setp 3. Create a php page function .php

    Inside this simple page a using class DB_concreate or define. Db_con class contain simple database connection and some insert funtion.

    function .php

    Setp 4.Define a oject and class the insert funtion

    Put this source code at the top of the simple root file index.php page

    insert($user_fname,$email,$user_mobile,$user_gender,$user_edu,$adrss);
    	if($sql)
    	{
    	echo "alert('USER Data inserted');";
    	}
    	else
    	{
    	echo "alert('USER Data not inserted');";
    	}
    }
     ?>
    

    Example

    I hope you have Got What is Objects Orientation in PHP And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.

    Laravel Get Last 7 days month year record from MySQL 0

    Laravel Get Last 7 days month year record

    Today, We want to share with you Laravel Get Last 7 days month year record from MySQL.In this post we will show you get last 7 days data from current date laravel, hear for How to get last 7 days record from table as per date using Laravel and MySQL we will give you demo and example for implement.In this post, we will learn about Selecting all records created last month with Eloquent with an example.

    Laravel Get Last 7 days month year record from MySQL

    There are the Following The simple About Laravel Get Last 7 days month year record from MySQL Full Information With Example and source code.

    As I will cover this Post with live Working example to develop laravel last 7 days query, so the some major files and Directory structures for this example is following below.

    • laravel carbon last 7 days
    • get last 7 days data in laravel without carbon

    How to get last 7 days data using Laravel 5.7?

    $mygetdate = \Carbon\Carbon::today()->subDays(30);
    $members = Member::where('created_at', '>=', $mygetdate)->get();
    dd($members);
    

    Get last 7 days data in laravel without Carbon

    Laravel search for records 7 days old only

    $members = Member::whereRaw('DATE(AppDate) = DATE_SUB(CURDATE(), INTERVAL 7 DAY)')
    

    use whereDate

    ->whereDate('created_at', Carbon::now()->subDays(7))
    ->get();
    

    Get results from 30 days ago in Laravel

    $members = Member::where('created_at', '>=', $date)->get();
    

    Angular 6 CRUD Operations Application Tutorials

    Search Retalted :get last 7 days data in laravel, laravel carbon last 7 days, laravel last 7 days query, eloquent last 7 days, subtract days laravel, laravel carbon last 7 days, get last 7 days data from current date laravel

    Read :

    Summary

    You can also read about AngularJS, ASP.NET, VueJs, PHP.

    I hope you get an idea about Laravel Get Last 7 days, month, year record from MySQL.
    I would like to have feedback on my Pakainfo.com blog.
    Your valuable feedback, question, or comments about this article are always welcome.
    If you enjoyed and liked this post, don’t forget to share.

    Laravel Drop hascolumn if exists in Migration 0

    Laravel Drop hascolumn if exists in Migration

    Today, We want to share with you Laravel Drop hascolumn if exists in Migration.In this post we will show you laravel eloquent check if record exists, hear for laravel check if model has column we will give you demo and example for implement.In this post, we will learn about how to create table through migration in laravel with an example.

    Laravel Drop hascolumn if exists in Migration

    There are the Following The simple About Laravel Drop hascolumn if exists in Migration Full Information With Example and source code.

    As I will cover this Post with live Working example to develop Laravel Migrations – Dropping columns, so the laravel check if column exists for this example is following below.

    Laravel drop column using migration.

    And then here We are going to explain how to drop column step by step.

    We can display we can use simple hasColumn(), as We can display below:

    Schema::hasColumn(my_db_table_name, my_column_name);
    

    And then We can display below full Laravel migration source code with example:

    <?php
    use Illuminate\Support\Facades\Schema;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Database\Migrations\Migration;
    class CreateUsersTable extends Migration
    {
        public function up()
        {
            Schema::table('products', function (Blueprint $table) {
                $table->increments('id');
                $table->string('product_name');
                $table->string('p_code')->unique();
                $table->string('p_rate');
                $table->rememberToken();
                $table->timestamps();
    			
            });
        }
        public function down()
        {
            if (Schema::hasColumn('products', 'product_name'))
            {
                Schema::table('products', function (Blueprint $table)
                {
                    $table->dropColumn('product_name');
                });
            }
        }
    }
    

    Last step To run the Database migration using command prompt.

    php artisan migrate:rollback
    

    Example 2: Laravel – Drop column if exists using migration

    How to check column exists or not in table Laravel 5.7

    if (Schema::hasColumn('subscriptions', 'stripe_id')) {
        Schema::table('subscriptions', function ($table) {
            $table->dropColumn('stripe_id');
        });
    }
    

    Angular 6 CRUD Operations Application Tutorials

    Read :

    Summary

    You can also read about AngularJS, ASP.NET, VueJs, PHP.

    I hope you get an idea about Laravel Drop hascolumn if exists in Migration.
    I would like to have feedback on my Pakainfo.com blog.
    Your valuable feedback, question, or comments about this article are always welcome.
    If you enjoyed and liked this post, don’t forget to share.