Laravel 6 insert query Example

Today, We want to share with you Laravel 6 insert query Example.In this post we will show you how to edit a record in laravel, hear for delete data from database in laravel we will give you demo and example for implement.In this post, we will learn about how to update data in mysql using laravel with an example.

Laravel 6 insert query Example

There are the Following The simple About how to retrieve data from database in laravel Full Information With Example and source code.

As I will cover this Post with live Working example to develop show data by id laravel, so the Insert Update and Delete record from MySQL in Laravel is used for this example is following below.

Laravel insert Query Example

Example 1: Laravel database insert query

$values = array('id' => 1,'name' => 'Mobile');
DB::table('products')->insert($values);

Example 2: Insert record from MySQL in Laravel

 public static function insertData($data){
    $value=DB::table('products')->where('productname', $data['productname'])->get();

    if($value->count() == 0){
      DB::table('products')->insert($data);
      return 1;
     }else{
       return 0;
     }
 
  }

 ///
 
$name = $request->input('name');
$productname = $request->input('productname');
$pcode = $request->input('pcode');

if($name !='' && $productname !='' && $pcode != ''){
$data = array('name'=>$name,"productname"=>$productname,"pcode"=>$pcode);

// Insert
$value = Product::insertData($data);

if($value){
  Session::flash('message','Insert Product successfully.');
}else{
  Session::flash('message','ProductName already exists.');
}

} 
Web Programming Tutorials Example with Demo

Read :

Summary

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

I hope you get an idea about insert data laravel 6.0 eloquent.
I would like to have feedback on my infinityknow.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.

Leave a Comment