本文整理汇总了PHP中Illuminate\Database\Eloquent\Collection::push方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::push方法的具体用法?PHP Collection::push怎么用?PHP Collection::push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Collection
的用法示例。
在下文中一共展示了Collection::push方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addTrainingData
public function addTrainingData($user, $training)
{
$collection = new Collection();
$visible = true;
foreach ($training as $itemKey => $item) {
$item['visible'] = $visible;
foreach ($item['relations'] as $relationKey => $relation) {
$done = true;
foreach ($relation as $elementKey => $element) {
$element['id'] = "{$item['id']}.{$element['id']}";
$element['watch-url'] = route('training.watch', ['year' => 2016, 'item' => $element['id']]);
$element['watched'] = Watched::where('subscription_id', $user->id)->where('item_id', $element['id'])->first();
$element['visible'] = $visible || $element['watched'];
$done = $done && $element['watched'];
if ($relationKey == 'quiz') {
$element['answer'] = $element['watched'] ? $element['watched']->answer : null;
}
$visible = $element['watched'] !== null;
$item['relations'][$relationKey][$elementKey] = $element;
}
}
$item['done'] = $done;
$collection->push($item);
}
return $collection;
}
示例2: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$month = new Carbon($this->argument('month'));
$billboards = Billboard::activated()->get();
$pictures = Storage::files();
$missing_pictures = new Collection();
foreach ($billboards as $billboard) {
$facings = $billboard->facings->all();
foreach ($facings as $facing) {
$ref = $this->reference($billboard, $facing, $month);
$image_url = "{$ref}.jpg";
if (in_array($image_url, $pictures)) {
try {
$this->trackingRepository->create(['facing_id' => $facing->id, 'image_url' => $image_url, 'tracking_date' => $month, 'location_id' => $billboard->location_id]);
$this->info('Tracking #' . $ref . ' with image url ' . $image_url . ' created successfully.');
} catch (\Illuminate\Database\QueryException $e) {
$this->error('Tracking #' . $ref . ' already exists.');
}
} else {
$this->error('Facing #' . $ref . ' picture missing.');
$missing_pictures->push(["name" => $facing->name, "image_url" => $image_url]);
}
}
}
if (!$missing_pictures->isEmpty()) {
$this->notifyMissingPictures($missing_pictures, "it@sagaciresearch.com");
}
}
示例3: getMaps
/**
*
* $newsletter
*/
protected function getMaps()
{
$posts = new Collection();
$projects = new Collection();
$this->each(function ($widget) use($projects, $posts) {
if ($widget->resource) {
if ($widget->resource_type == Post::class) {
$posts->push($widget->resource_id);
}
if ($widget->resource_type == Project::class) {
$projects->push($widget->resource_id);
}
}
if ($widget->other_resource) {
if ($widget->other_resource_type == Post::class) {
$posts->push($widget->other_resource_id);
}
if ($widget->other_resource_type == Project::class) {
$projects->push($widget->other_resource_id);
}
}
});
$posts = Post::whereIn('posts.id', $posts->all())->with(['translations', 'images', 'images.sizes'])->get();
$projects = Project::whereIn('portfolio_projects.id', $projects->all())->with(['translations', 'images', 'images.sizes'])->get();
return [$posts, $projects];
}
示例4: show
/**
* Display the specified resource.
*
* @param int|null $id
*
* @return \Illuminate\Http\Response
*/
public function show($id = null)
{
if ($id === null) {
$profile = Auth::user()->getProfile();
} else {
$profile = Profile::findOrFail($id);
}
$is_mine = $profile->user_id == \Flocc\Auth::getUserId();
if ($is_mine === true) {
$activities = (new Activities())->get();
$tribes = (new Tribes())->get();
$events_time_lines = new Collection();
foreach ($profile->getTimeLine()->getLatestUpdatedEvents() as $event) {
foreach ($event->getTimeLine() as $line) {
if ($line->isMessage()) {
$events_time_lines->push(['id' => $event->getId(), 'slug' => $event->getSlug(), 'event' => $event->getTitle(), 'date' => $line->getTime(), 'message' => $line->getMessage()]);
}
}
}
$events_time_lines = $events_time_lines->sortByDesc('date')->slice(0, 5);
return view('dashboard', compact('profile', 'is_mine', 'activities', 'tribes', 'events_time_lines'));
} else {
return view('profiles.show', compact('profile', 'is_mine', 'id'));
}
}
示例5: maps
public function maps($tournament)
{
$maps = new Collection();
$this->reports($tournament)->get()->each(function ($report) use(&$maps) {
$maps->push(Map::find($report->map));
});
return $maps;
}
示例6: fire
public function fire()
{
$pushWords = new Collection();
$dayWord = WordCard::find(Setting::first()->word_id);
$pushWords->push(['word_id' => $dayWord->id, 'category_id' => $dayWord->category_id]);
Category::all()->each(function ($category) use($pushWords) {
$this->info("looking at category {$category->id}");
$word = $this->getSentWord($category);
if ($word) {
$pushWords->push(['word_id' => $word->id, 'category_id' => $category->id]);
} else {
$this->error('Empty category');
}
});
$this->check();
$this->pushWords2($pushWords);
}
示例7: routes
/**
* @return Collection
*/
public function routes()
{
$routes = new Collection();
foreach ($this->items as $module) {
foreach ($module->routes as $route) {
$routes->push($route);
}
}
return $routes;
}
示例8: sortByLikes
private function sortByLikes(Collection $collection, Collection $orderArray)
{
$sorted = new Collection();
$orderArray->each(function ($orderElem) use($collection, $sorted) {
if ($collection->contains($orderElem->likeable_id)) {
$sorted->push($collection->find($orderElem->likeable_id));
}
});
return $sorted;
}
示例9: testSerializeNested
public function testSerializeNested()
{
$obj = new RESTModelStub();
$fooobj = new RESTModelStub();
$fooobj->foo = 'bar';
$collection = new Collection();
$collection->push($fooobj);
$obj->setRelation('foos', $collection);
$serializer = new BaseSerializer();
$this->assertEquals(array('fred' => array('foos' => array(array('foo' => 'bar')))), $serializer->serialize($obj, 'fred'));
}
示例10: getDashboard
public function getDashboard()
{
$favorites = Favorite::whereUserId(Auth::user()->id)->get();
$collection = new Collection();
foreach ($favorites as $favorite) {
$content = new Content('layout_movie');
$object = $content->wherePageId($favorite->page_id)->whereContentIdentifier($favorite->content_identifier)->first();
if ($object) {
$collection->push($object);
}
}
return $collection;
}
示例11: testOverrideLink
public function testOverrideLink()
{
Config::shouldReceive('get')->with('andizzle/rest-framework::page_limit')->andReturn('5');
REST::shouldReceive('getApiPrefix')->andReturn('api/v1');
$obj = new RESTModelStub();
$fooobj = new RESTModelStub();
$fooobj->id = 1;
$fooobj->root = 'roots';
$collection = new Collection();
$obj->setSideLoads(array('foos'));
$collection->push($fooobj);
$obj->setRelation('foos', $collection);
$serializer = new HyperlinkedJSONSerializer();
$serializer->setURLOverrides(array('foos' => 'fredId=1'));
$this->assertEquals(array('fred' => array('links' => array('foos' => 'api/v1/roots?fredId=1'))), $serializer->serialize($obj, 'fred'));
}
示例12: getHome
public function getHome()
{
$services = \App\Service::all();
$categories = \Auth::user()->categories;
$servicesnp = new Collection();
foreach ($services as $service) {
$service->name = '(' . $service->category->name . ')-' . $service->name;
}
foreach ($categories as $category) {
foreach ($category->services as $service) {
$service->name = '(' . $service->category->name . ')-' . $service->name;
$servicesnp->push($service);
}
}
return view('pages.home', compact('services', 'servicesnp'));
}
示例13: testSerializeNoEmbed
public function testSerializeNoEmbed()
{
Config::shouldReceive('get')->with('andizzle/rest-framework::page_limit')->andReturn('5');
Config::shouldReceive('get')->with('andizzle/rest-framework::serializer.embed-relations')->once()->andReturn(false);
$obj = new RESTModelStub();
$obj->foo = 'bar';
$fooobj = new RESTModelStub();
$fooobj->id = 1;
$fooobj->root = 'roots';
$collection = new Collection();
$obj->setSideLoads(array('foos'));
$collection->push($fooobj);
$obj->setRelation('foos', $collection);
$serializer = new JSONSerializer();
$this->assertEquals(array('fred' => array('foo' => 'bar', 'foos' => array('1'))), $serializer->serialize($obj, 'fred'));
}
示例14: run
public function run()
{
foreach ([1, 2] as $account) {
$teller = 0;
$teams = new Collection();
while ($teller < 3) {
$teams->push(Team::create(['account_id' => $account, 'nl' => ['name' => $this->faker->sentence(2), 'description' => $this->faker->paragraph(5)], 'en' => ['name' => $this->faker->sentence(2), 'description' => $this->faker->paragraph(5)], 'fr' => ['name' => $this->faker->sentence(2), 'description' => $this->faker->paragraph(5)], 'de' => ['name' => $this->faker->sentence(2), 'description' => $this->faker->paragraph(5)]]));
$teller++;
}
$account = Account::find($account);
$teams = array_flip($teams->lists('id')->toArray());
foreach ($account->memberships as $membership) {
$membership->teams()->attach(array_rand($teams, rand(1, 3)));
}
}
}
示例15: save
/**
*
*/
public function save()
{
if (empty($this->data)) {
return;
}
if ($this->relation instanceof Relations\HasMany && is_array($this->data)) {
if (is_numeric($this->data[0])) {
$data = new Collection();
foreach ($this->data as $key => $item) {
// $this->data[$key] = $this->related->baseModel->find($item);
$data->push($this->related->baseModel->find($item));
}
} else {
$data = new Collection($this->data);
}
// detach any existing models and only save the selected ones
$foreignKey = $this->relation->getPlainForeignKey();
$current = $this->relation->getResults();
if (!$current) {
$this->relation->saveMany($data->toArray());
return;
}
$all = $data->merge($current);
foreach ($all as $item) {
if ($keep = $data->find($item->getKey())) {
$this->relation->save($keep);
} else {
$item->{$foreignKey} = null;
$item->save();
}
}
} else {
if ($this->relation instanceof Relations\BelongsToMany && is_array($this->data)) {
if (is_numeric($this->data[0])) {
$this->relation->sync($this->data);
}
} else {
/* If we have an id let's grab the model instance, otherwise assume we were given it */
$this->data = is_numeric($this->data) ? $this->related->baseModel->find($this->data) : $this->data;
parent::saveRelation($this->relation, $this->data);
}
}
}