Exemple #1
0
 /**
  * Montar estrutura de busca pelo $searchQuery.
  *
  * @param $searchQuery
  *
  * @return array
  */
 public function execute($searchQuery)
 {
     if (count($this->fields) == 0) {
         return [];
     }
     if ($searchQuery == '') {
         return [];
     }
     $searchQuery = Str::ascii($searchQuery);
     $tokens = $this->tokens($searchQuery);
     $list = [];
     foreach ($this->fields as $key => $field) {
         $type = $this->model->getAttrCast($key);
         $method = sprintf('field%s', Str::studly($type));
         $field = $this->prepareField($field);
         if (method_exists($this, $method)) {
             if (array_key_exists($key, $list) != true) {
                 $list[$key] = [];
             }
             call_user_func_array([$this, $method], [&$list[$key], $field, $tokens]);
         }
     }
     return $list;
 }
Exemple #2
0
 public function hasGetMutator($key)
 {
     return method_exists($this, 'get' . Str::studly($key) . 'Attribute');
 }
Exemple #3
0
 /**
  * Carregar campos do request para o modelo.
  *
  * @param $model
  * @param Request $request
  * @param array $references
  */
 public function apply($model, Request $request, array $references)
 {
     // Carregar valores informados
     $all = $request->all();
     // Verificar se deve ignorar o campo de debug
     if (array_key_exists('XDEBUG_SESSION_START', $all)) {
         unset($all['XDEBUG_SESSION_START']);
     }
     // Verificar referencias
     $all = $this->loadReferences($all, $references);
     // Aplcar campos
     foreach ($all as $name => $value) {
         if ($this->hasApply($name)) {
             // Verificar se tem que tratar aplicação
             $type = $model->getAttrCast($name);
             $method = sprintf('apply%s', Str::studly($type));
             if (method_exists($this, $method)) {
                 call_user_func_array([$this, $method], [$model, $name, $value, $request]);
             } else {
                 $this->applyString($model, $name, $value, $request);
             }
         }
     }
     // Verificar "multassociations" não informados
     foreach ($model->getCasts() as $key => $type) {
         if ($type == 'multassociations' && array_key_exists($key, $all) != true) {
             $this->applyMultassociations($model, $key, [], $request);
         }
     }
 }
Exemple #4
0
 /**
  * POST: Command /{id}/{comand}.
  */
 public function command()
 {
     return DB::transaction(function () {
         // Carregar parametros
         $id = $this->getRouteId();
         $command = Route::input('command');
         // Carregar model
         $this->model = $this->getModel($id);
         $method = 'command' . Str::studly($command);
         if (method_exists($this, $method) != true) {
             error('Comando %s não foi implementado', $command);
         }
         return call_user_func_array([$this, $method], [$id]);
     });
 }