Example #1
0
 public function testWithValidIdFilter()
 {
     $this->initDB();
     $exitCode = Artisan::call('permission:show', ['permission' => $this->list->get(0)->id]);
     $this->assertEquals($exitCode, 0);
     $output = Artisan::output();
     foreach (['Id', 'Name', 'Description'] as $el) {
         $this->assertContains($el, $output);
     }
 }
 /**
  * @param array $setting
  * @return mixed
  * @throws Exception
  */
 protected function settingGetType(array $setting)
 {
     if (!static::$types) {
         static::$types = ThemeSettingType::all()->keyBy('name');
     }
     if (!static::$types->has($setting['type'])) {
         throw new Exception('Invalid setting type provided');
     }
     return static::$types->get($setting['type']);
 }
Example #3
0
 public function testWithValidIdFilter()
 {
     $this->initDB();
     $exitCode = Artisan::call('ticket:show', ['ticket' => $this->ticketList->get(1)->id]);
     $this->assertEquals($exitCode, 0);
     $output = Artisan::output();
     $fields = ['Id', 'Ip', 'Domain', 'Class id', 'Type id', 'Last notify timestamp'];
     foreach ($fields as $el) {
         $this->assertContains($el, $output);
     }
 }
Example #4
0
 /**
  * Finally delete content item
  */
 public function make()
 {
     // remove gallery files if exists
     foreach ($this->_records->get() as $record) {
         $galleryPath = '/upload/gallery/' . (int) $record->id;
         if (Directory::exist($galleryPath)) {
             Directory::remove($galleryPath);
         }
     }
     // finally remove from db
     $this->_records->forceDelete();
 }
Example #5
0
 /**
  * Simulate a get clause on the collection.
  *
  * @param  mixed  $key
  * @param  mixed  $default
  * @return mixed
  */
 public function get($key = null, $default = null)
 {
     if (is_null($key) and is_null($default)) {
         return $this;
     }
     return parent::get($key, $default);
 }
Example #6
0
 /**
  * Remove a meta key
  *
  * @param $key
  */
 public function deleteMeta($key)
 {
     $this->loadMetaData();
     /** @var Data $meta */
     $meta = $this->metaData->get($key, null);
     if (!is_null($meta)) {
         $meta->deleteOnSave();
     }
 }
 /**
  * Get notFoundManyException.
  * @param $ids
  * @param Collection $models
  * @param string $keyName
  * @return ValidationExceptionCollection
  */
 protected function notFoundManyException($ids, $models, $keyName = '')
 {
     $errors = [];
     $models->keyBy($keyName);
     foreach ($ids as $id) {
         if ($models->get($id)) {
             $errors[] = null;
         } else {
             $errors[] = $this->notFoundException($keyName);
         }
     }
     throw new ValidationExceptionCollection($errors);
 }
Example #8
0
 /**
  * Create a collection of models from a request collection
  * The method is more efficient if is passed a Collection of existing entries otherwise it will do a query for every entity.
  * @param array $requestCollection
  * @param EloquentCollection|null $existingModels
  * @return Collection
  */
 public function hydrateRequestCollection(array $requestCollection, EloquentCollection $existingModels = null)
 {
     $keyName = $this->getKeyName();
     $models = array_map(function ($item) use($keyName, $existingModels) {
         /** @var Model $model */
         $model = null;
         $entityId = isset($item[$keyName]) ? $item[$keyName] : null;
         //if we have known models, get the model from the collection
         if ($existingModels) {
             $model = $existingModels->get($entityId);
         }
         //if the model couldn't be found, find it in the database directly, or create a new one
         if (!$model) {
             $model = $this->findOrNew($entityId);
         }
         $model->fill($item);
         return $model;
     }, $requestCollection);
     return $this->newCollection($models);
 }
Example #9
0
 public static function choose_from_collection(\Illuminate\Database\Eloquent\Collection $collection)
 {
     assert($collection->count(), 'Collection empty!');
     return $collection->get($collection->keys()[mt_rand() % $collection->count()]);
 }
Example #10
0
 /**
  * 处理上方所有条件后, 执行查询语句, 返回结果集
  *
  * @param array $columns 默认获取全部字段
  * @return mixed
  */
 protected function selectQuery(array $columns = []) : \Illuminate\Support\Collection
 {
     return $this->original->get($columns);
 }