Created
January 23, 2019 06:05
-
-
Save prondubuisi/8eb884a2721f82987975d9355ee85f7a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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