コード例 #1
0
 /**
  * @param  \Illuminate\Database\Query\Builder|\Minhbang\Kit\Extensions\Model $query
  * @param bool $position
  *
  * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
  */
 protected function optionAppliedPaginate($query, $position = false)
 {
     list($column, $direction) = $this->options->column('sort');
     if ($column) {
         $query->orderBy($column, $direction);
     } else {
         if ($position) {
             $query->orderPosition();
         }
     }
     return $query->paginate($this->options->get('page_size', 6));
 }
コード例 #2
0
 /**
  * Ví dụ đối với enum 'language'
  * - Attribute của model: language_id
  * - Khi $model->present()->language: tự động lấy 'title' của enum đó
  * - Khi $model->present()->language_params: tự động lấy 'params' của enum đó
  *
  * @param string $property
  *
  * @return mixed
  */
 public function __get($property)
 {
     if (method_exists($this, $property)) {
         return $this->{$property}();
     } else {
         if (substr($property, -7) === '_params') {
             // get enum params
             $property_id = substr($property, 0, -7) . '_id';
             $column = 'params';
         } else {
             // get enum title
             $property_id = "{$property}_id";
             $column = 'title';
         }
         if (in_array($property_id, $this->entity->getEnumAttributes())) {
             return $this->entity->getEnumValue($property_id, $column);
         } else {
             // fallback to model
             return $this->entity->{$property};
         }
     }
 }
コード例 #3
0
ファイル: User.php プロジェクト: minhbang/laravel-simple-user
 /**
  * Hàm 'động' kiểm tra role, vd:
  * $user->role = 'editor', check: $user->isEditor() => true
  * $user->role = 'super_admin', check: $user->isSuperAdmin() => true
  *
  * @param string $method
  * @param array $parameters
  *
  * @return mixed
  */
 public function __call($method, $parameters)
 {
     return starts_with($method, 'is') ? $this->is(snake_case(substr($method, 2)), $parameters ? $parameters[0] : false) : parent::__call($method, $parameters);
 }
コード例 #4
0
ファイル: Ebook.php プロジェクト: minhbang/laravel-ebook
 /**
  * Ebook constructor.
  *
  * @param array $attributes
  */
 public function __construct(array $attributes = [])
 {
     parent::__construct($attributes);
     $this->config(['featured_image' => config('ebook.featured_image')]);
 }