예제 #1
0
 public function firstOrFail()
 {
     $item = $this->first();
     if ($item === null) {
         throw new ModelNotFoundException(ucfirst(Str::camelize($this->model->getTable())) . ' was not found');
     }
     return $item;
 }
예제 #2
0
파일: Model.php 프로젝트: skipperbent/pecee
 public function toArray()
 {
     $rows = $this->results['rows'];
     if ($rows && is_array($rows)) {
         foreach ($rows as $key => $row) {
             $key = isset($this->rename[$key]) ? $this->rename[$key] : $key;
             if (in_array($key, $this->hidden)) {
                 unset($rows[$key]);
                 continue;
             }
             $rows[$key] = $this->parseArrayData($row);
         }
         $this->orderArrayRows($rows);
     }
     if (count($this->getResults()) === 1) {
         foreach ($this->with as $with) {
             $method = Str::camelize($with);
             if (!method_exists($this, $method)) {
                 throw new ModelException('Missing required method ' . $method);
             }
             $output = call_user_func([$this, $method]);
             $with = isset($this->rename[$with]) ? $this->rename[$with] : $with;
             $rows[$with] = $output instanceof self || $output instanceof ModelCollection ? $output->toArray() : $output;
         }
         return $rows;
     }
     return $rows;
 }