Advertisement
deCreative

Example Ajax Filter

Feb 21st, 2019
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. ====== Route ========
  2.  
  3. Route::get('/products','ProductController@index');
  4.  
  5. ===== Controller : ProductController =========
  6. public function index(Request $request){
  7.  
  8. $products = Product::latest();
  9. if($request->has('filter)){
  10. // Filter sesuai Kebutuhan
  11. $products = Product::orderBy('cols','asc/desc');
  12. }
  13.  
  14. if($request->ajax(){
  15.     return view('layouts.products.ajax',compact('products');
  16. }else{
  17.     return view('layouts.products.index',compact('products');
  18. }
  19.  
  20. }
  21.  
  22.  
  23. ============ index.blade.php
  24.  
  25. // Form INput select box
  26.     <select id="filter" name="filter">
  27.         //Option dan Value
  28.     </select>
  29. //
  30.  
  31. <div id="dataProduct">
  32.     // Tampilkan data saat index.
  33. </div>
  34.  
  35. <script type="text/javascript>
  36.     //Buat Javascipt Ajax get data filter
  37.     success:function(response){
  38.         $("#dataProduct").html(response);
  39.     },
  40.     error:function(response{
  41.         console.log(response);
  42.     }
  43. <script>
  44.  
  45. ============== ajax.blade.php
  46.  
  47. hanya berisi :
  48.  
  49. <div id="dataProduct">
  50.     // Tampilkan data saat index.
  51. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement