Advertisement
bernandotorrez

CarModelTable.php

Nov 1st, 2020
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.09 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Livewire;
  4.  
  5. use App\Models\CarModel;
  6. use Illuminate\Database\Eloquent\Builder;
  7. use Rappasoft\LaravelLivewireTables\TableComponent;
  8. use Rappasoft\LaravelLivewireTables\Traits\HtmlComponents;
  9. use Rappasoft\LaravelLivewireTables\Views\Column;
  10. use App\Repository\Eloquent\Repo\CarModelRepository;
  11.  
  12. class CarModelTable extends TableComponent
  13. {
  14.     use HtmlComponents;
  15.  
  16.     public $perPage = 10;
  17.  
  18.     protected $options = [
  19.         // The class set on the table when using bootstrap
  20.         'bootstrap.classes.table' => 'table table-striped table-bordered',
  21.    
  22.         // The class set on the table's thead when using bootstrap
  23.         'bootstrap.classes.thead' => null,
  24.    
  25.         // The class set on the table's export dropdown button
  26.         'bootstrap.classes.buttons.export' => 'btn',
  27.        
  28.         // Whether or not the table is wrapped in a `.container-fluid` or not
  29.         'bootstrap.container' => true,
  30.        
  31.         // Whether or not the table is wrapped in a `.table-responsive` or not
  32.         'bootstrap.responsive' => true,
  33.     ];
  34.  
  35.     public function query() : Builder
  36.     {
  37.         return CarModel::query();
  38.     }
  39.  
  40.     public function columns() : array
  41.     {
  42.         return [
  43.             Column::make('ID', 'id')
  44.                 ->searchable()
  45.                 ->sortable(),
  46.             Column::make('Name', 'desc_model')
  47.                 ->searchable()
  48.                 ->sortable(),
  49.             Column::make('Action')
  50.                 ->format(function(CarModel $model) {
  51.                     return $this->html('<button class="btn" wire:click="deleteCarModel('.$model->id.')"><i class="fas fa-trash-alt text-danger"></i> Delete</button>');
  52.                 })
  53.         ];
  54.     }
  55.  
  56.     public function deleteCarModel($id, CarModelRepository $carModelRepository)
  57.     {
  58.         $delete = $carModelRepository->delete($id);
  59.  
  60.         if($delete) {
  61.             $this->delete_status = 'success';
  62.             $this->car_model_data = $carModelRepository->all();
  63.         } else {
  64.             $this->delete_status = 'fail';
  65.         }
  66.  
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement