Skip to content

Instantly share code, notes, and snippets.

@prondubuisi
Created January 23, 2019 06:05
Show Gist options
  • Save prondubuisi/8eb884a2721f82987975d9355ee85f7a to your computer and use it in GitHub Desktop.
Save prondubuisi/8eb884a2721f82987975d9355ee85f7a to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Controllers;
use App\Product as Product;
use Illuminate\Http\Request;
class ProductController extends Controller
{
public function index()
{
return view('products');
}
public function search(Request $request)
{
if($request->ajax()){
$output="";
$products = Product::where('title','LIKE','%'.$request->search."%")->get();
if($products){
foreach ($products as $product) {
$output.='<tr>'.
'<td>'.$product->id.'</td>'.
'<td>'.$product->title.'</td>'.
'<td>'.$product->description.'</td>'.
'<td>'.$product->price.'</td>'.
'</tr>';
}
return $output;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment