Esempio n. 1
0
 /**
  * Handle the command.
  */
 public function handle()
 {
     $this->builder->fire('saving', ['builder' => $this->builder]);
     $repository = $this->builder->getGridRepository();
     $repository->save($this->builder);
     $this->builder->fire('saved', ['builder' => $this->builder]);
 }
 /**
  * Get the grid entries.
  *
  * @param GridBuilder $builder
  * @return Collection
  */
 public function get(GridBuilder $builder)
 {
     // Start a new query.
     $query = $this->model->newQuery();
     /**
      * Prevent joins from overriding intended columns
      * by prefixing with the model's grid name.
      */
     $query = $query->select($this->model->getTable() . '.*');
     /**
      * Eager load any relations to
      * save resources and queries.
      */
     $query = $query->with($builder->getGridOption('eager', []));
     /**
      * Raise and fire an event here to allow
      * other things (including filters / views)
      * to modify the query before proceeding.
      */
     $builder->fire('querying', compact('builder', 'query'));
     app('events')->fire(new GridIsQuerying($builder, $query));
     /**
      * Before we actually adjust the baseline query
      * set the total amount of entries possible back
      * on the grid so it can be used later.
      */
     $total = $query->count();
     $builder->setGridOption('total_results', $total);
     /**
      * Order the query results.
      */
     foreach ($builder->getGridOption('order_by', ['sort_order' => 'asc']) as $column => $direction) {
         $query = $query->orderBy($column, $direction);
     }
     return $query->get();
 }