You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

24 lines
650 B

<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Product;
use Illuminate\Http\Request;
class ProductsController extends Controller
{
public function search(Request $request)
{
$query = $request->get('query');
$queriedProducts = [];
if ($query) {
$queriedProducts = Product::where(function ($q) use ($query) {
$q->where('name', 'like', '%'.$query.'%');
})->with('unit')->get();
}
return response()->json($queriedProducts, 200);
// return view('cart.partials.product-search-result-box', $queriedProducts);
}
}