当前位置: 首页>>代码示例>>PHP>>正文


PHP Collection::make方法代码示例

本文整理汇总了PHP中Illuminate\Database\Eloquent\Collection::make方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::make方法的具体用法?PHP Collection::make怎么用?PHP Collection::make使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Database\Eloquent\Collection的用法示例。


在下文中一共展示了Collection::make方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: serializeKeys

 /**
  * Serialize all toManys to keys
  *
  * @param ArrayableInterface $instance
  * @return $instance
  */
 public function serializeKeys(ArrayableInterface $instance)
 {
     $is_collection = True;
     $result = new Collection();
     if (!$this->isCollection($instance)) {
         $is_collection = False;
         $collection = new Collection();
         $instance = $collection->add($instance);
     }
     $instance->transform(function ($item) {
         $side_loads = $item->getSideLoads();
         foreach ($side_loads as $load) {
             $relation = $item->{$load};
             $item->__unset($load);
             if (!$this->isEmptyOrNull($relation)) {
                 if ($relation instanceof Collection) {
                     // If is a collection then the result is a list of
                     // id. e.g: [1, 2, 3]
                     $item->setRelation($load, Collection::make($relation->unique()->modelKeys()));
                 } else {
                     // otherwise the result is an id. e.g: 2
                     $item->setAttribute($load, $relation->getKey());
                 }
             }
         }
         return $item;
     });
     if (!$is_collection) {
         return $instance->pop();
     }
     return $instance;
 }
开发者ID:andizzle,项目名称:rest-framework,代码行数:38,代码来源:JSONSerializer.php

示例2: findByName

 /**
  * Return a Collection of countries with the name given.
  * @param  String $name Country name
  * @return Collection   Collection of countries.
  */
 public function findByName($name)
 {
     if (!is_string($name)) {
         return Collection::make([]);
     }
     return $this->where('name', $name)->get();
 }
开发者ID:filmoteca,项目名称:filmoteca,代码行数:12,代码来源:Country.php

示例3: function

 /** @test */
 function it_creates_a_form_with_fields()
 {
     $builder = $this->getBuilder();
     $this->assertFileNotExists($builder->getClassFilePath('project'));
     $builder->build('project', Collection::make([NodeField::create(['name' => 'description', 'type' => 'text', 'description' => 'Some hints', 'label' => 'Project Description', 'rules' => '\'required|max:5000\'', 'default_value' => '\'Texty text\'', 'position' => 1, 'search_priority' => 10]), NodeField::create(['name' => 'type', 'type' => 'select', 'description' => 'Some hints for type', 'label' => 'Project Type', 'position' => 2, 'options' => "'choices' => [1 => 'Housing', 2 => 'Cultural'], 'selected' => function(\$data) {return 1;}, 'empty_value' => '---no type---'", 'search_priority' => 0])]));
     $this->assertFileExists($builder->getClassFilePath('project'));
 }
开发者ID:NuclearCMS,项目名称:Hierarchy,代码行数:8,代码来源:FormBuilderTest.php

示例4: index

 /**
  * Ce controller à pour but de gérer la logique de recherche d'un film dans la base de données
  * Le controller gère aussi les topics lorsque l'utilisateur fait une recherche via les checkboxes sur
  * la page de d'affichage des résultats.
  * Les fonctions paginate servent à créer le paginator qui est simplement l'affichage des films 20 par 20.
  *
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $search = Input::get('search');
     $topics = Input::except('search', 'page');
     if (empty($topics)) {
         // Pas de topics on renvoie simplement les films correspondants
         $allMovies = Movies::where('title', 'like', "%{$search}%")->paginate(20)->appends(Input::except('page'));
     } else {
         // SI on a des topics dans l'input il est nécessaire de filtrer
         $movies = Topics::whereIn('topic_name', $topics)->with('movies')->get();
         $moviesCollection = Collection::make();
         foreach ($movies as $movy) {
             $moviesCollection->add($movy->movies()->where('title', 'like', "%{$search}%")->get());
         }
         $moviesCollection = $moviesCollection->collapse();
         // Il n'est pas possible de créer la paginator directement, on le crée donc à la main
         $page = Input::get('page', 1);
         $perPage = 20;
         $offset = $page * $perPage - $perPage;
         $allMovies = new LengthAwarePaginator($moviesCollection->slice($offset, $perPage, true), $moviesCollection->count(), $perPage);
         $allMovies->setPath(Paginator::resolveCurrentPath());
         $allMovies->appends(Input::except('page'));
     }
     // A la vue correspondante on lui renvoie une liste des films correspondants à la recherche, le tout paginé
     return view('search', compact('allMovies'));
 }
开发者ID:Tirke,项目名称:ShortMovies,代码行数:35,代码来源:SearchController.php

示例5: getFilters

 /**
  * Get Table Filter
  *
  * @author WN
  * @return Collection
  */
 protected function getFilters()
 {
     if (!$this->filters) {
         $this->filters = Collection::make(Request::capture()->except(['limit', 'page', 'download']));
     }
     return $this->filters;
 }
开发者ID:paybreak,项目名称:basket,代码行数:13,代码来源:FilterTrait.php

示例6: findByCategory

 /**
  * Find news by category identifier
  *
  * @param $slug
  * @param int $page
  * @return Collection
  */
 public function findByCategory($slug, $page = 1)
 {
     if ($category = $this->fetchCategory($slug)) {
         return $category->news()->with('categories')->take($this->perPage)->forPage($page)->orderBy('created_at', 'desc')->get();
     }
     return Collection::make([]);
 }
开发者ID:adminarchitect,项目名称:news,代码行数:14,代码来源:NewsRepository.php

示例7: __construct

 /**
  * Create a new command instance.
  *
  * @return void
  */
 public function __construct()
 {
     $this->country = App::make('Filmoteca\\Models\\Exhibitions\\Country');
     $this->film = App::make('Filmoteca\\Models\\Exhibitions\\Film');
     $this->genre = App::make('Filmoteca\\Models\\Exhibitions\\Genre');
     $this->newGenres = Collection::make([]);
     parent::__construct();
 }
开发者ID:filmoteca,项目名称:filmoteca,代码行数:13,代码来源:ImportFilmsFromExcelCommand.php

示例8: permissions

 /**
  * Return an array of permissions through roles
  *
  * @return Collection
  **/
 public function permissions()
 {
     $permissions = [];
     foreach ($this->roles as $role) {
         $permissions = array_merge($permissions, $role->perms->toArray());
     }
     return Collection::make($permissions);
 }
开发者ID:alexhouse,项目名称:trust,代码行数:13,代码来源:UserRoleTrait.php

示例9: index

 /**
  * Display a listing of the resource.
  * @param \App\Criteria $criteria
  * @return \Illuminate\Http\Response
  */
 public function index(Criteria $criteria)
 {
     $criteria->load(['options', 'options.langs', 'langs']);
     $options = $criteria->options()->sort()->get();
     $criteria = $this->loadLangs(Collection::make([$criteria]))->first();
     $options = $this->loadLangs($options);
     return view('admin.criteria.option.index', ['title' => $criteria->dbLangs->get(dbTrans())->title . ' ' . trans('static.options'), 'url' => action('Admin\\CriteriaOptionController@create', [$criteria->id]), 'back' => action('Admin\\CriteriaController@index'), 'options' => $options, 'criteria' => $criteria]);
 }
开发者ID:Tisho84,项目名称:conference,代码行数:13,代码来源:CriteriaOptionController.php

示例10: makeCollection

 protected function makeCollection(ResultSet $resultSet)
 {
     $models = [];
     foreach ($resultSet as $row) {
         $params = array_merge($row['friends']->getProperties(), ['id' => $row['friends']->getId()]);
         $models[] = $this->model->newFromBuilder($params);
     }
     return Collection::make($models);
 }
开发者ID:prasol,项目名称:socialrest,代码行数:9,代码来源:UserRepository.php

示例11: getTimesAttribute

 public function getTimesAttribute()
 {
     $result = \Illuminate\Database\Eloquent\Collection::make();
     foreach ($this->tickets as $ticket) {
         foreach ($ticket->times as $time) {
             $result->push($time);
         }
     }
     return $result;
 }
开发者ID:bhargavjoshi,项目名称:timesheet,代码行数:10,代码来源:User.php

示例12: getSpeakersAttribute

 public function getSpeakersAttribute()
 {
     if (!$this->speakers) {
         foreach ($this->speakers_pivot()->get() as $pivot) {
             /** @var EventSpeaker $pivot */
             $this->speakers[] = $pivot->user;
         }
         $this->speakers = Collection::make($this->speakers);
     }
     return $this->speakers;
 }
开发者ID:konato-events,项目名称:web,代码行数:11,代码来源:Session.php

示例13: getWithProducts

 /**
  * Returns all products contained in the orders associated with a freeproduct
  * @return freeproducts collection of all the products contained in the orders associated with freeproduct, but defined as a property of the model
  */
 public static function getWithProducts(Collection $items)
 {
     $freeproducts = $items->each(function ($item, $key) {
         $list_products_orders = Collection::make();
         foreach ($item->orders as $order) {
             $list_products_orders = $list_products_orders->merge($order->products);
         }
         $item->products = $list_products_orders;
     });
     return $freeproducts;
 }
开发者ID:masterpowers,项目名称:antVel,代码行数:15,代码来源:FreeProduct.php

示例14: test_map_correctly_maps_results_to_models

 public function test_map_correctly_maps_results_to_models()
 {
     $client = Mockery::mock('Elasticsearch\\Client');
     $engine = new ElasticsearchEngine($client, 'scout');
     $model = Mockery::mock('Illuminate\\Database\\Eloquent\\Model');
     $model->shouldReceive('getKeyName')->andReturn('id');
     $model->shouldReceive('whereIn')->once()->with('id', ['1'])->andReturn($model);
     $model->shouldReceive('get')->once()->andReturn(Collection::make([new ElasticsearchEngineTestModel()]));
     $results = $engine->map(['hits' => ['total' => '1', 'hits' => [['_id' => '1']]]], $model);
     $this->assertEquals(1, count($results));
 }
开发者ID:ericktamayo,项目名称:laravel-scout-elastic,代码行数:11,代码来源:ElasticsearchEngineTest.php

示例15: deleteDestroy

 public function deleteDestroy()
 {
     $modelArray = array();
     $deleteModels = Input::json('models');
     foreach ($deleteModels as $model) {
         $deleteComputerClassroom = ComputerClassroom::find($model['id']);
         $deleteComputerClassroom->delete();
         array_push($modelArray, $deleteComputerClassroom);
         $returnModels = BaseCollection::make($modelArray);
     }
     echo $returnModels->toJson();
 }
开发者ID:p-tricky,项目名称:CAEWeb,代码行数:12,代码来源:ComputerClassroomController.php


注:本文中的Illuminate\Database\Eloquent\Collection::make方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。