Topic: Mysql

PHP AJAX Live Search Box Autocomplete Using MySQL Database 0

PHP AJAX Live Search Box Autocomplete Using MySQL Database

Today, We want to share with you PHP AJAX Live Search Box Autocomplete Using MySQL Database.In this post we will show you PHP Jquery AJAX Live Search Box Using MySQL, hear for PHP MySQL Live Search Box using Jquery Ajax Example we will give you demo and example for implement.In this post, we will learn about Jquery Ajax Live Search Box using PHP MySql with an example.

PHP AJAX Live Search Box Autocomplete Using MySQL Database

There are the Following The simple About PHP AJAX Live Search Box Autocomplete Using MySQL Database Full Information With Example and source code.

As I will cover this Post with live Working example to develop ajax live data search using jquery php mysql, so the some major files and Directory structures for this example is following below.

  • index.php
  • fetch.php

Step 1: Creating the Database Table

— Database: `member_list` >> — Table structure for table `member_tbl`

CREATE TABLE IF NOT EXISTS `member_tbl` (
  `MemberID` int(11) NOT NULL AUTO_INCREMENT,
  `MemberName` varchar(250) NOT NULL,
  `member_addr` text NOT NULL,
  `member_city` varchar(250) NOT NULL,
  `member_pcode` varchar(30) NOT NULL,
  `member_country` varchar(100) NOT NULL,
  PRIMARY KEY (`MemberID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ;

Step 2: Dumping data On Table

Dumping data for table `member_tbl`

//ajax live data search using jquery php mysql
INSERT INTO `member_tbl` (`MemberID`, `MemberName`, `member_addr`, `member_city`, `member_pcode`, `member_country`) VALUES
(1, 'Jaydeep Gondaliya', 'sejal Str. 57', 'Berlin', '12209', 'Germany'),
(2, 'Ankit Kathiriya', 'Avda. de la Ram park 2222', 'USA D.F.', '5021', 'USA'),
(3, 'Krunal Sisodiya', 'sardha 2312', 'USA D.F.', '5475', 'USA'),
(4, 'chirag dethariya', '120 dsp salon Sq.', 'London', 'WA1 1DP', 'UK'),
(5, 'Dhaval dave', 'Rua do Ganesh, 12', 'Resende', '56458-363', 'UEA'),
(6, 'Pooja solanki', 'ul. astha 68', 'Walla', '01-658', 'Poland'),
(7, 'Bhakti Banugariya', 'kavya 45', 'Helsinki', '2853', 'India'),
(8, 'Nilesh chandvadiya', '305 - 14th Ave. S. Suite 3B', 'Seattle', '98128', 'USA'),
(9, 'Hitesh Ajani', 'Rua do Ganesh, 12', 'Resende', '098952-363', 'UEA'),
(10, 'Mayur Dhameliya', 'bhakti 38', 'Oulu', '321452', 'India'),
(11, 'Stavan Patel', '2, rue du chandni', 'Reims', '350024', 'France'),
(12, 'Parag shukla', '722 Titupati Blvd.', 'Kirkland', '360002', 'USA'),
(13, 'Vijay bhanderi', 'Bhavanath. 48', 'Butte', '225010', 'USA');

Step 3: Creating the Search Form

index.php

This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as index.php.

 
  
  <title>PHP AJAX Live Search Box Autocomplete Using MySQL Database</title>
  
  
  
 
 
  <div class="pakainfo container">
   <br />
   <h2 align="center">PHP AJAX Live Search Box Autocomplete Using MySQL Database</h2>
   
   <b>Simple ajax live data search using jquery php mysql</b><br />
   <div class="pakainfo form-group">
    <div class="input-group pakainfo">
     <span class="input-group-addon pakainfo">Search</span>
     
    </div>
   </div>
   <br />
   <div id="result"></div>
  </div>
 


$(document).ready(function(){

 ajax_data_load();

 function ajax_data_load(query)
 {
  $.ajax({
   url:"fetch.php",
   method:"POST",
   data:{query:query},
   success:function(data)
   {
    $('#result').html(data);
   }
  });
 }
 $('#query_search').keyup(function(){
  var search = $(this).val();
  if(search != '')
  {
   ajax_data_load(search);
  }
  else
  {
   ajax_data_load();
  }
 });
});

Step 4 : Processing Search Query in Backend

fetch.php for PHP AJAX Live Search Box Autocomplete server side source code

 0)
{
 $output .= '
  <div class="pakainfo table-responsive">
   <table class="table table bordered">
    <tr>
     <th>Member Name</th>
     <th>member Address</th>
     <th>member_city</th>
     <th>Member Post Code</th>
     <th>member_country</th>
    </tr>
 ';
 while($memres = mysqli_fetch_array($result))
 {
  $output .= '
   <tr>
    <td>'.$memres["MemberName"].'</td>
    <td>'.$memres["member_addr"].'</td>
    <td>'.$memres["member_city"].'</td>
    <td>'.$memres["member_pcode"].'</td>
    <td>'.$memres["member_country"].'</td>
   </tr>
  ';
 }
 echo $output;
}
else
{
 echo 'Data Not Found';
}

?>

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 PHP AJAX Live Search Box Autocomplete Using MySQL Database.
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.

Difference between two dates in years, months, days in PHP 0

Difference between two dates in years, months, days in PHP

Today, We want to share with you Difference between two dates in years, months, days in PHP.In this post we will show you calculate the difference between two dates in PHP, hear for PHP Get difference between two dates in years months days hours minutes we will give you demo and example for implement.In this post, we will learn about php difference between two dates in years months and days with an example.

Difference between two dates in years, months, days in PHP

There are the Following The simple About Difference between two dates in years, months, days in PHP Full Information With Example and source code.

As I will cover this Post with live Working example to develop calculate days between two dates in php, so the PHP Date Exercises Time difference php calculate time difference between two dates in minutes for this example is following below.

PHP Difference Between Two Dates

PHP Date Exercises Time difference in days and years, months, days, hours, minutes, seconds between two dates

$first_date = new DateTime('2019-06-01 02:12:51');
$second_date = new DateTime('2023-05-12 11:10:00');
$live_date_diff = $first_date->diff($second_date);
echo $live_date_diff->days.'Total days'."\n";
echo $live_date_diff->y.' years'."\n";
echo $live_date_diff->m.' months'."\n";
echo $live_date_diff->d.' days'."\n";
echo $live_date_diff->h.' hours'."\n";
echo $live_date_diff->i.' minutes'."\n";
echo $live_date_diff->s.' seconds'."\n";

You can also make a single simple PHP function/Methods to fetch difference between two dates using PHP in years months, days, hours and minutes that will be very helpful for all some filter data or chart or any project. We won’t need to re-write the source code.

//get Simple difference between two dates in years months, days, hours and minute
$live_date_diff = getDateDiff('2019-06-01 02:12:51','2022-05-12 11:10:00');

print_r($live_date_diff);

function getDateDiff($first_date,$second_date) {
    $first_date = new DateTime($first_date);
    $second_date = new DateTime($second_date);
    $live_date_diff = $first_date->diff($second_date);
    
    $nodeResult['total_days'] = $live_date_diff->days;
    $nodeResult['years'] = $live_date_diff->y;
    $nodeResult['months'] = $live_date_diff->m;
    $nodeResult['days'] = $live_date_diff->d;
    $nodeResult['hours'] = $live_date_diff->h;
    $nodeResult['minutes'] = $live_date_diff->i;
    $nodeResult['seconds'] = $live_date_diff->s ;
    return $nodeResult;
}

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 Difference between two dates in years, months, days in PHP.
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.

PHP OOP CRUD MVC Framework Tutorial 0

PHP OOP CRUD MVC Framework Tutorial

Today, We want to share with you PHP OOP CRUD MVC Framework Tutorial.
In this post we will show you php Simple MVC example with source code, hear for CRUD with PHP OOP and MVC we will give you demo and example for implement.
In this post, we will learn about Simple PHP MVC Framework Example with an example.

Welcome to the In Pakainfo.com website! You will Step By Step learn web programming, easy and very fun. This website allmost provides you with a complete web programming tutorial presented in an easy-to-follow manner. Each web programming tutorial has all the practical examples with web programming script and screenshots available.php Simple MVC example with source code

Folder Structure :

******************
===================
MVC
->controller
–>Controller.php
->model
–>user.php
–>Model.php
->view
–>userlist.php
–>viewuser.php
index.php
===================

Source code : Simple php mvc example

index.php

invoke();

?>

Controller.php

username = $username;
	    $this->userfname = $userfname;
	    $this->userinfo = $userinfo;
    } 
}

?>

user.php

username = $username;
	    $this->userfname = $userfname;
	    $this->userinfo = $userinfo;
    } 
}

?>

Model.php

 new Users("only playing", "R. dismelp", "student of the atmiya."),
			"Ravi Korat" => new Users("Moonwalker", "J. Walker", "stud. of th rk collage"),
			"Pragnesh shah" => new Users("hitesh dhameliya", "news boys", "choklate boys")
		);
	}
	public function getBook($username)
	{
		$allBooks = $this->getUserList();
		return $allBooks[$username];
	}
}
?>

userlist.php

<title>php Simple MVC example with source code</title>

<table>
	<tr><td>User Name</td><td>UserFirstName</td><td>UserInfo</td></tr>
	 $users)
		{
			echo '<tr><td><a>username.'">'.$users->username.'</a></td><td>'.$users->userfname.'</td><td>'.$users->userinfo.'</td></tr>';
		}

	?>
</table>


viewuser.php



<title>php Simple MVC example with source code</title>


username . '<br />';
	echo 'userfname:' . $user->userfname . '<br />';
	echo 'userinfo:' . $user->userinfo . '<br />';
?>



MVC run : http://localhost/mvc/

PHP sleep delay Function increasing execution time 0

PHP sleep delay Function increasing execution time

Today, We want to share with you PHP sleep delay Function increasing execution time.In this post we will show you Php, wait 5 seconds before executing an action, hear for jQuery delay Effects with Animation Example we will give you demo and example for implement.In this post, we will learn about Adding delay to the script execution time in PHP by using PHP sleep function with an example.

PHP sleep delay Function increasing execution time

There are the Following The simple About PHP sleep delay Function increasing execution time Full Information With Example and source code.

As I will cover this Post with live Working example to develop Delay, sleep, pause, wait etc in PHP, so the delay(sleep) a PHP function call using PHP for this example is following below.

PHP sleep() Function

The PHP sleep() methods delays some execution of the active script for a (delay)specified number of seconds.

Syntax

sleep(seconds)

Using PHP sleep to add some times delay or increase your script execution time

sleep(25);

The above PHP command will make a PHP delay of 25 seconds, the next process of script execution will be after the some delay of 25 seconds.

Simple PHP sleep delay Examples

Let us print some time the time after a delay(sleep) a PHP function call using PHP of 15 seconds.

<?php
echo date('H:i:s');
sleep(15);
flush();
echo "<br>";
echo date('H:i:s');
?>

Out of the two Simple php sleepoutpus , second one will return display after 15 secs

12:22:19
--------------
12:22:34

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 PHP sleep delay Function increasing execution time.
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.

Fetch Last week month year records in MySQL 0

Fetch Last week month year records in MySQL

Today, We want to share with you Fetch Last week month year records in MySQL.In this post we will show you How to fetch this week records in MySql ?, hear for SELECT IN MYSQL CURRENT DAY, CURRENT WEEK, LAST WEEK we will give you demo and example for implement.In this post, we will learn about Last one week, month, year record from date field by DATE_SUB with an example.

Fetch Last week month year records in MySQL

There are the Following The simple About Fetch Last week month year records in MySQL Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel Get Last 7 days month year record from MySQL, so the get this week records mysql,fetch current week records mysql for this example is following below.

If We require to get all the MySQL Database records of current week using mysql query. for example We have one SQL table “products” as well as all the columns are product_id, product_title, product_description, created_at as well as update_at timestemp, And then We need to fetch all records of this week. therefor We can fetch all the fields value using DATE_SUB and INTERVAL of simple mysql Table. In following simple example We can display how to MySQL select data of fetch current week.

SELECT * FROM products WHERE created_at > DATE_SUB(NOW(), INTERVAL 1 WEEK);

Last 10 days records

select * from products where  `date` >= DATE_SUB(CURDATE(), INTERVAL 10 DAY)

DATE_SUB() Fetch the recent one month or year records from PHP MySQL table

SELECT DATE_SUB(  '2019-12-25', INTERVAL 3 DAY )

Present Month Records

SELECT * FROM `products` WHERE  date between  DATE_FORMAT(CURDATE() ,'%Y-%m-01') AND CURDATE()

Present Year Records

SELECT * FROM `products` WHERE  date between  DATE_FORMAT(CURDATE() ,'%Y-01-01') AND CURDATE()

Last one month records

select * from products where  `date` >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH)

Records of two date ranges

select * from products where `date` BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 3 MONTH ) AND DATE_SUB( CURDATE( ) ,INTERVAL 0 MONTH )

Fetch records between 6 month and 12 month

select * from products where `date` BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 12  MONTH ) AND DATE_SUB( CURDATE( ) ,INTERVAL 6 MONTH )

MYSQL CURRENT DAY

SELECT IN MYSQL CURRENT DAY, CURRENT WEEK, LAST WEEK

Selecting MySQL records for the current day:

SELECT *
FROM (`products`)
WHERE date = CURDATE()  

MYSQL CURRENT week

SELECT IN MYSQL CURRENT DAY, CURRENT WEEK, LAST WEEK

Selecting MySQL records for the current week:

SELECT SUM(o_price) price
FROM (`orders`)
WHERE YEARWEEK(`o_date`) = YEARWEEK(CURDATE()) 

MYSQL CURRENT week

SELECT IN MYSQL CURRENT DAY, CURRENT WEEK, LAST WEEK

Selecting MySQL records for the current week:

SELECT *
FROM (
`products`
)
WHERE YEARWEEK( `date` ) = YEARWEEK( CURDATE( ) + INTERVAL 1 WEEK )
LIMIT 0 , 30

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 Fetch Last week month year records in 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 Eloquent query where exists MySQL 0

Laravel Eloquent query where exists

Today, We want to share with you Laravel Eloquent query where exists.In this post we will show you Laravel 5 query builder where exists example, hear for Check If A Database Table Exists With Laravel we will give you demo and example for implement.In this post, we will learn about Laravel Advance Database Query Builder with an example.

Laravel Eloquent query where exists

There are the Following The simple About Laravel Eloquent query where exists Full Information With Example and source code.

As I will cover this Post with live Working example to develop PHP SQL exists in Laravel 5 query builder, so the Laravel Eloquent – WhereNotExists for this example is following below.

We use simple Code PHP sql where exists clause in check laravel. whereExists through We can use Database in sql where exists clause in Latest version of the laravel Web project. It is simple and very easy to use as well as We can best way to implements and undestand. We can give simple fire SELECT statment in where some condition. We can see bellow source code with example as well as We can learn how to use simple whereExists in your Laravel app.

Simple SQL Query

SELECT *
FROM `products`
WHERE EXISTS
    (SELECT `products_cat`.`id`
     FROM `products_cat`
     WHERE products_cat.cat_id = products.id)

MySQL Using Laravel Query Builder

DB::table('products')
    ->whereExists(function ($query) {
        $query->select("products_cat.id")
              ->from('products_cat')
              ->whereRaw('products_cat.cat_id = products.id');
    })
    ->get();

Example 2: SQL exists in Laravel 5 query builder

$product = Products::whereNotExists(function ($query) use ($id_merchant) {
	$query->select(DB::raw(1))
		  ->from('merchant_poeni')
		  ->where('product.id', '=', 'a.id')
		  ->where('product_id', '=', $id_merchant);
})
->orderBy('created_at')
->first();

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 Eloquent query where exists.
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.

PHP MySQL Column Sorting Examples 0

PHP MySQL Column Sorting Examples

Today, We want to share with you PHP MySQL Column Sorting Examples.In this post we will show you Column Sorting using PHP and MySQL, hear for Server-side Processing DataTables using PHP with MySQL we will give you demo and example for implement.In this post, we will learn about Laravel Datatable Pagination Sorting and Search server side processing with an example.

PHP MySQL Column Sorting Examples

There are the Following The simple About PHP MySQL Column Sorting Examples Full Information With Example and source code.

As I will cover this Post with live Working example to develop Jquery Datatable listing json Server side in Php Mysql and Ajax, so the sorting data from database in php for this example is following below.

Create products table:

Here, we will create products table by following sql query:

CREATE TABLE IF NOT EXISTS `products` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(80) NOT NULL,
  `srno` varchar(244) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

Create index.php file:

<!DOCTYPE html>
<html>
<head>
  <title>Column Sorting using PHP and MySQL - pakainfo.com</title>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" />
</head>
<body>
 
<div class="container">
  <h1>Column Sorting using PHP and MySQL - pakainfo.com</h1>
  <p>MySQL ORDER BY - Sort a Result Set in MySQL using PHP Examples</p>
<?php
     
    $hostName = "localhost";
    $db_uname = "atmiya";
    $db_pass = "jaydeepGondaliya";
    $dbname = "inv_system"; 
    $mysqli = new mysqli($hostName, $db_uname, $db_pass, $dbname); 
    $productOrderby = !empty($_GET["orderby"]) ? $_GET["orderby"] : "name";
 
    $order = !empty($_GET["order"]) ? $_GET["order"] : "asc";
 
    $sql = "SELECT * FROM products ORDER BY " . $productOrderby . " " . $order;
  
    $result = $mysqli->query($sql);
  
    $order_Name = "asc";
    $srnoOrder = "asc";
  
    if($productOrderby == "name" && $order == "asc") {
      $order_Name = "desc";
    }
    if($productOrderby == "srno" && $order == "asc") {
      $srnoOrder = "desc";
    }
?>
<table class="table table-bordered">
  <thead>
    <tr>
      <th><a href="?orderby=name&order=<?php echo $order_Name; ?>">Product Name</a></th>
      <th><a href="?orderby=srno&order=<?php echo $srnoOrder; ?>">SR.NO</a></th>
    </tr>
  </thead>
  <tbody>
  
    <?php
    while($row = mysqli_fetch_assoc($result)){
    ?>
      <tr>
        <td><?php echo $row['name']; ?></td>
        <td><?php echo $row['srno']; ?></td>
      </tr>
    <?php
    }
    ?>
  
  </tbody>
</table>
  
</div>
  
</body>
</html>

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 PHP MySQL Column Sorting Examples.
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.

PHP Yii Maintenance Mode Tutorial with Examples 0

PHP Yii Maintenance Mode Tutorial with Examples

Today, We want to share with you PHP Yii Maintenance Mode Tutorial with Examples.
In this post we will show you Yii Maintenance Mode, hear for Programming With Yii2: Routing and URL Creation we will give you demo and example for implement.
In this post, we will learn about php – yii toggle maintenance mode ON/OFF with an example.

The Yii Maintenance ModeAny User can simple Display access maintenance Mode or file only View in HTML Page.

  • The Yii Maintenance Controller
  • The Yii Maintence File

The Yii Maintenance Controller

Create or Point the Yii Simple controller main Logix action to page display maintenance mode.

return array(
    'catchAllRequest'=> array('site/yii_maintenance'),
    ............   

The Yii Maintence File

Create or Point the Yii sersver side file to maintenance or processing mode. If the check simple condition here Like PHP functions file_exists() return boolean value false, The PHP Based yii maintenance mode will be simple check switch off or not work.

'catchAllRequest'=>file_exists(dirname(__FILE__).'/.yii_maintenance')? array('site/yii_maintenance') : null,

Read :

Summary

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

I hope you get an idea about How to implement “Maintenance Mode” in Yii.
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.

jQuery Ajax CRUD operations in Laravel 5.7 0

jQuery Ajax CRUD operations in Laravel 5.7

Today, We want to share with you jQuery Ajax CRUD operations in Laravel 5.7.In this post we will show you ajax crud operations in laravel 5.7 with modal & pagination, hear for Laravel 5.7 Ajax CRUD with Pagination example and demo from scratch we will give you demo and example for implement.In this post, we will learn about Laravel 5.7 Ajax CRUD example for web application without page refresh with an example.

jQuery Ajax CRUD operations in Laravel 5.7

There are the Following The simple About jQuery Ajax CRUD operations in Laravel 5.7 Full Information With Example and source code.

As I will cover this Post with live Working example to develop Ajax CRUD example in Laravel 5.7 application, so the laravel 5.7 ajax update database for this example is following below.

Step 1: Install Laravel 5.7

Run the below Laravel command to install laravel Latest version Like Laravel 5.7,

Composer create-project --prefer-dist laravel/laravel crud

Step 2: Setup MySQL Database Configuration

We can do all the database setup step by step configuration on .env file.

Step 3: Create Table

Comment to create table,

php artisan make:migration create_products_table --create=product

Now, Go to path “database/migrations” and here We can simple change the migration file of product table,

<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateproductsTable extends Migration
{
    public function up()
    {
        Schema::create('products', function(Blueprint $table)
        {
            $table->increments('id');
            $table->string('name');
            $table->string('description');
            $table->timestamps();
        });
    }
    public function down()
    {
        Schema::dropIfExists('products');
    }
}
 

After that we can Use the below PHP artisan command to migrate.

php artisan migrate

Step 4: Creating Laravel 5.7 Controller

Run the below simple command to create a Laravel controller as well as Laravel model,

php artisan make:controller ProductController --resource --model=Model/Product

We can display the created Laravel controller Path on “app/Http/Controllers/”

Step 5: Define a Laravel Routes

And then, We simple Run the following PHP artisan command to include the routes inside the file name web.php file of routes folder.

Route::resource('product','ProductController');

Step 6: Make a Laravel Default Methods In Product Controller

  • Index()
  • Create()
  • Store()
  • Show()
  • Edit()
  • Update()
  • Destroy()

Above All the Laravel methods are the default methods in ProductController

Step 7: Write The source Code For Laravel 5.7 CRUD Operation

And then We can display the All step by step process of CRUD operation in Laravel 5.7,

<?php
namespace App\Http\Controllers;
use App\Model\Product;
use Illuminate\Http\Request;
class ProductController extends Controller {
    public function index() {
        $products = Product::latest()->paginate(5);
        return view('products.index', compact('products'))->with('i', (request()->input('page', 1) - 1) * 5);
    }
    public function create() {
        return view('products.create');
    }
    public function store(Request $request) {
        $request->validate(['name' => 'required', 'description' => 'required', ]);
        Product::create($request->all());
        return redirect()->route('products.index')->with('success', 'product created successfully.');
    }
    public function show(Product $Product) {
        return view('products.show', compact('product'));
    }
    public function edit(Product $Product) {
        return view('products.edit', compact('product'));
    }
    public function update(Request $request, Product $Product) {
        $Product->validate(['name' => 'required', 'description' => 'required', ]);
        $product->update($request->all());
        return redirect()->route('products.index')->with('success', 'product updated successfully');
    }
    public function destroy(Product $Product) {
        $Product->delete();
        return redirect()->route('products.index')->with('success', 'product deleted successfully');
    }
}

Step 8: making a blade files In Laravel 5.7

We have Total 5 blade files,

  • Layout.blade.php
  • Index.blade.php
  • Create.blade.php
  • Edit.blade.php
  • Show.blade.php

Layout.blade.php

<!DOCTYPE html>
<html>
  <head>
    <title>Welcome To Pakainfo.com</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/css/bootstrap.css" rel="stylesheet">
  </head>
  <body>
    <div class="container">
      @yield('content')
    </div>
  </body>
</html>

Index.blade.php

@extends('product.layout')
@section('content')
<div class="row">
  <div class="col-lg-12 margin-tb">
    <div class="pull-left">
      <h2>Welcome
      </h2>
    </div>
    <div class="pull-right">
      <a class="btn btn-success" href="{{ route('products.create') }}"> Create New product
      </a>
    </div>
  </div>
</div>
@if ($message = Session::get('success'))
<div class="alert alert-success">
  <p>{{ $message }}
  </p>
</div>
@endif
<table class="table table-bordered">
  <tr>
    <th>Slno
    </th>
    <th>Name
    </th>
    <th>description
    </th>
    <th width="280px">Action
    </th>
  </tr>
  @foreach ($products as $product)
  <tr>
    <td>{{ ++$i }}
    </td>
    <td>{{ $product->name }}
    </td>
    <td>{{ $product->description }}
    </td>
    <td>
      <form action="{{ route('products.destroy',$product->id) }}" method="POST">
        <a class="btn btn-info" href="{{ route('products.show',$product->id) }}">Show
        </a>
        <a class="btn btn-success" href="{{ route('products.edit',$product->id) }}">Edit
        </a>
        @csrf
        @method('DELETE')
        <button type="submit" class="btn btn-danger">Delete
        </button>
      </form>
    </td>
  </tr>
  @endforeach
</table>
{!! $products->links() !!}
@endsection

Create.blade.php

@extends('products.layout')
@section('content')
<div class="row">
  <div class="col-lg-12 margin-tb">
    <div class="pull-left">
      <h2>Add New product
      </h2>
    </div>
    <div class="pull-right">
      <a class="btn btn-success" href="{{ route('products.index') }}"> Back
      </a>
    </div>
  </div>
</div>
@if ($errors->any())
<div class="alert alert-danger">
  <strong>Whoops!
  </strong> There were some problems with your input.
  <br>
  <br>
  <ul>
    @foreach ($errors->all() as $error)
    <li>{{ $error }}
    </li>
    @endforeach
  </ul>
</div>
@endif
<form action="{{ route('products.store') }}" method="POST">
  @csrf
  <div class="row">
    <div class="col-xs-12 col-sm-12 col-md-12">
      <div class="form-group">
        <strong>Name:
        </strong>
        <input type="text" name="name" class="form-control" placeholder="Name">
      </div>
    </div>
    <div class="col-xs-12 col-sm-12 col-md-12">
      <div class="form-group">
        <strong>Detail:
        </strong>
        <input type="text" name="description" class="form-control" placeholder="description">
      </div>
    </div>
    <div class="col-xs-12 col-sm-12 col-md-12 text-center">
      <button type="submit" class="btn btn-success">Submit
      </button>
    </div>
  </div>
</form>
@endsection

Edit.blade.php

@extends('products.layout')
@section('content')
<div class="row">
  <div class="col-lg-12 margin-tb">
    <div class="pull-left pakainfo">
      <h2>Edit product
      </h2>
    </div>
    <div class="pull-right pakainfo">
      <a class="btn btn-success" href="{{ route('products.index') }}"> Back
      </a>
    </div>
  </div>
</div>
@if ($errors->any())
<div class="alert alert-danger">
  <strong>Whoops!
  </strong> There were some More problems with your input.
  <br>
  <br>
  <ul>
    @foreach ($errors->all() as $error)
    <li>{{ $error }}
    </li>
    @endforeach
  </ul>
</div>
@endif
<form action="{{ route('products.update',$product->id) }}" method="POST">
  @csrf
  @method('PUT')
  <div class="row">
    <div class="col-xs-12 col-sm-12 col-md-12">
      <div class="form-group pakainfo">
        <strong>Name:
        </strong>
        <input type="text" name="name" value="{{ $product->name }}" class="form-control" placeholder="Name">
      </div>
    </div>
    <div class="col-xs-12 col-sm-12 col-md-12">
      <div class="form-group pakainfo">
        <strong>Detail:
        </strong>
        <input type="text" name="description" value="{{ $product->description }}" class="form-control" placeholder="description">
      </div>
    </div>
    <div class="col-xs-12 col-sm-12 col-md-12 text-center">
      <button type="submit" class="btn btn-success">Submit
      </button>
    </div>
  </div>
</form>
@endsection

Show.blade.php

@extends('products.layout')
@section('content')
<div class="row pakainfo">
  <div class="col-lg-12 margin-tb">
    <div class="pull-left">
      <h2> Show product
      </h2>
    </div>
    <div class="pull-right pakainfo">
      <a class="btn btn-success" href="{{ route('products.index') }}"> Back
      </a>
    </div>
  </div>
</div>
<div class="row">
  <div class="col-xs-12 col-sm-12 col-md-12">
    <div class="form-group pakainfo">
      <strong>Name:
      </strong>
      {{ $product->name }}
    </div>
  </div>
  <div class="col-xs-12 col-sm-12 col-md-12">
    <div class="form-group pakainfo">
      <strong>Details:
      </strong>
      {{ $product->description }}
    </div>
  </div>
</div>
@endsection

Last step You can Run the below php artisan command to run this project the local server

php artisan serve

Now We can display my local browsers server successfully running here http://localhost:8000/products

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 jQuery Ajax CRUD operations in Laravel 5.7.
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.

Bootstrap Toggle Inside JQuery DataTable 0

Bootstrap Toggle Inside JQuery DataTable

Today, We want to share with you Bootstrap Toggle Inside JQuery DataTable.In this post we will show you Bootstrap Switch / Toggle – examples, hear for bootstrap 4 toggle switch jQuery DataTables we will give you demo and example for implement.In this post, we will learn about How To Display Bootstrap Toggle Switch with DataTables via Render with an example.

Bootstrap Toggle Inside JQuery DataTable

There are the Following The simple About Bootstrap Toggle Inside JQuery DataTable Full Information With Example and source code.

Laravel Bootstrap Toggle switch Update DB field using Ajax

As I will cover this Post with live Working example to develop jQuery Datatable toggle filter, so the some major files and Directory structures for this example

Toggle Switches Laravel, Ajax and jQuery example

is following below.

DataTable Bootstrap Toggle

 <table id="saved-members-table" class="display responsive nowrap table table-striped table-bordered" width="100%" cellspacing="0">
<thead>
<tr><th><?php echo $global['client_name'];?></th> 
     <th><?php echo $global['phone'];?></th>
     <th>PC. No</th>
     <th>Membership Type</th>
     <th>Status</th>
 </tr>
</thead>
</table>

Laravel Toggle Switch Inside Bootstrap Ajax Example

HTML Part

<input id="live-toggle-example" type="checkbox" checked data-toggle="toggle" data-on="Active" data-off="Due" data-onstyle="success" data-offstyle="warning">

jQuery('#live-toggle-example').bootstrapToggle();

Laravel 5.7 Toggle switch Update DB field using Ajax

And then, the jQuery DataTable Server-side Processing JS source Code.

jQuery('#saved-members-table').DataTable({
    "processing": true,
    "serverSide": true,
    "ajax": "pakacodes.php?Members=yes", 
     "sScrollX": "100%", 
    aoColumns : [                          
        { "sWidth": "20%" },
        { "sWidth": "20%"},
        { "sWidth": "20%"},
        { "sWidth": "20%"},                           
        { "sWidth": "20%" }
    ],
"fnDrawCallback": function() {
    jQuery('#saved-members-table #live-toggle-example').bootstrapToggle();
}

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 Bootstrap Toggle Inside JQuery DataTable.
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.