本文整理汇总了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;
}
示例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();
}
示例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'));
}
示例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'));
}
示例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;
}
示例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([]);
}
示例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();
}
示例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);
}
示例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]);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
示例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();
}