Exemplo n.º 1
0
 public static function ofProjects(\Illuminate\Database\Eloquent\Collection $projects)
 {
     return static::whereIn('project_id', $projects->pluck('id'))->orderBy('created_at', 'desc');
 }
Exemplo n.º 2
0
 /**
  * Create abilities whose name is not in the given list.
  *
  * @param  \Illuminate\Database\Eloquent\Collection  $models
  * @param  array  $abilities
  * @param  array  $attributes
  * @return \Illuminate\Database\Eloquent\Collection
  */
 protected function createMissingAbilities(Collection $models, array $abilities, $attributes = [])
 {
     $missing = array_diff($abilities, $models->pluck('name')->all());
     $created = [];
     foreach ($missing as $ability) {
         $created[] = Models::ability()->create($attributes + ['name' => $ability]);
     }
     return $created;
 }
Exemplo n.º 3
0
 /**
  * Create abilities whose name is not in the given list.
  *
  * @param  \Illuminate\Database\Eloquent\Collection  $models
  * @param  array  $abilities
  * @return \Illuminate\Database\Eloquent\Collection
  */
 protected function createMissingAbilities(Collection $models, array $abilities)
 {
     $missing = array_diff($abilities, $models->pluck('name')->all());
     $created = [];
     foreach ($missing as $ability) {
         $created[] = Ability::create(['name' => $ability]);
     }
     return $created;
 }
Exemplo n.º 4
0
 /**
  * Create a new job instance.
  *
  * @param Collection $requests
  * @param string $token Access token for Vk.com API
  */
 public function __construct(Collection $requests, $token)
 {
     $this->requests = $requests;
     $this->token = (string) $token;
     VkRequest::whereIn('id', $requests->pluck('id')->all())->delete();
 }
Exemplo n.º 5
0
 /**
  * Get the user's role names.
  *
  * @return string
  */
 public function formatRoles()
 {
     $this->loadRoles();
     return $this->cachedRoles->pluck('name')->implode(', ');
 }
Exemplo n.º 6
0
 /**
  * Get an array with the values of a given column.
  *
  * @param  string  $column
  * @param  string  $key
  * @return array
  */
 public function lists($column, $key = null)
 {
     $columns = $this->getListSelect($column, $key);
     // First we will just get all of the column values for the record result set
     // then we can associate those values with the column if it was specified
     // otherwise we can just give these values back without a specific key.
     $res = $this->get($columns);
     $results = new Collection($res->getData());
     $values = $results->pluck($columns[0])->all();
     // If a key was specified and we have results, we will go ahead and combine
     // the values with the keys of all of the records so that the values can
     // be accessed by the key of the rows instead of simply being numeric.
     if (!is_null($key) && count($results) > 0) {
         $keys = $results->pluck($key)->all();
         return array_combine($keys, $values);
     }
     return $values;
 }
Exemplo n.º 7
0
 /**
  * Append Campaign data to the supplied collection.
  *
  * @param  \Illuminate\Database\Eloquent\Collection  $collection
  * @return \Illuminate\Database\Eloquent\Collection
  */
 protected function appendCampaignToCollection($collection)
 {
     $campaignIds = $collection->pluck('campaign_id')->all();
     $campaigns = $this->campaignRepository->getAll($campaignIds);
     $campaigns = $campaigns->keyBy('id')->all();
     foreach ($collection as $contest) {
         if (isset($campaigns[$contest->campaign_id])) {
             $contest->setAttribute('campaign', $campaigns[$contest->campaign_id]);
         } else {
             $contest->setAttribute('campaign', null);
         }
     }
     return $collection;
 }
Exemplo n.º 8
0
 /**
  * Create permissions whose name is not in the given list.
  *
  * @param  \Illuminate\Database\Eloquent\Collection  $models
  * @param  array  $permissions
  * @return \Illuminate\Database\Eloquent\Collection
  */
 protected function createMissingPermissions(Collection $models, array $permissions)
 {
     $missing = array_diff($permissions, $models->pluck('name')->all());
     $created = [];
     foreach ($missing as $permission) {
         $created[] = Models::permission()->create(['name' => $permission]);
     }
     return $created;
 }