本文整理汇总了PHP中Illuminate\Database\Eloquent\Collection类的典型用法代码示例。如果您正苦于以下问题:PHP Collection类的具体用法?PHP Collection怎么用?PHP Collection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Collection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: 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];
}
开发者ID:jaffle-be,项目名称:framework,代码行数:30,代码来源:CampaignWidgetCollection.php
示例2: create
public function create(Request $request, $student_id = null)
{
$message_types = $this->message_type->orderBy('message_type_name')->lists('message_type_name', 'id')->all();
$schools = $this->school->lists('school_name', 'id')->all();
if (isset($student_id)) {
$student = $this->contact->find($student_id);
} else {
$student = null;
}
$all_contacts = $this->contact->allStudents();
$contacts = array();
foreach ($all_contacts as $contact) {
$contacts[$contact->id] = $contact->name . ' ' . $contact->surname;
}
if ($request->input('message_id')) {
$messages = Message::processIds($request->input('message_id'));
} else {
$selected = null;
}
$students = new Collection();
$selected = array();
if (isset($messages)) {
foreach ($messages as $message) {
$students->add($message->Contact);
$selected[] = $message->Contact->id;
}
$students = $students->unique();
}
return view()->make('messages.create', compact('message_types', 'schools', 'contacts', 'student', 'selected'));
}
开发者ID:mikeminckler,项目名称:unilog,代码行数:30,代码来源:MessagesController.php
示例3: render
/**
* Render the likes into a string.
*
* @param Collection $likesCollection The likes to render.
*
* @param string $viewAllLikesLink The link to view all of the likes for the content.
*
* @return string
*/
public function render(Collection $likesCollection, $viewAllLikesLink)
{
$numLikesToList = $this->settings->get('posts.likes_to_show', 3);
$numOtherLikes = $likesCollection->count() - $numLikesToList;
$userId = $this->guard->user()->getAuthIdentifier();
$likes = [];
$likesCollection = $likesCollection->filter(function (Like $like) use(&$likes, &$numLikesToList, $userId) {
if ($like->user->id === $userId) {
$like->user->name = $this->lang->get('likes.current_user');
$likes[] = $like;
$numLikesToList--;
return false;
}
return true;
});
$numLikesInCollection = $likesCollection->count();
if ($numLikesInCollection > 0 && $numLikesToList > 0) {
if ($numLikesInCollection < $numLikesToList) {
$numLikesToList = $numLikesInCollection;
}
$randomLikes = $likesCollection->random($numLikesToList);
if (!is_array($randomLikes)) {
// random returns a single model if $numLikesToList is 1...
$randomLikes = array($randomLikes);
}
foreach ($randomLikes as $key => $like) {
$likes[] = $like;
}
}
return $this->viewFactory->make('likes.list', compact('numOtherLikes', 'likes', 'viewAllLikesLink'))->render();
}
开发者ID:Adamzynoni,项目名称:mybb2,代码行数:40,代码来源:RenderLikes.php
示例4: update_groupe_post
public function update_groupe_post(Request $request, $id)
{
$user = Auth::user();
if ($user->profil->intitule == "administrateur") {
$erreurs = new Collection();
$this->validate($request, ['intitule' => 'required', 'description' => 'required', 'parcours' => 'exists:parcours,id']);
$groupes = Groupe::all();
$groupe = Groupe::find($id);
foreach ($groupes as $g) {
if ($request->input('intitule') != $groupe->intitule) {
if ($request->input('intitule') == $g->intitule) {
$erreurs->prepend("Cet intitulé existe déjà !");
break;
}
}
}
$groupe->intitule = $request->input('intitule');
$groupe->description = $request->input('description');
$groupe->parcours_id = $request->input('parcours');
$parcours = Parcours::all();
if (count($erreurs) > 0) {
return response()->view('groupe/update_groupe', ['groupe' => $groupe, 'erreurs' => $erreurs, 'parcours' => $parcours]);
}
$groupe->save();
return redirect('admin/groupe');
}
return "Vous êtes pas administrateur";
}
开发者ID:ATBTeam,项目名称:optionnelles,代码行数:28,代码来源:GroupeController.php
示例5: collection
public function collection(Collection $collection)
{
$this->data = $collection->map(function ($item) {
return $this->makeData($item);
})->all();
return $this;
}
开发者ID:jackweinbender,项目名称:laravel-jsonapi,代码行数:7,代码来源:JsonApi.php
示例6: update_profil_post
public function update_profil_post(Request $request, $id)
{
$user = Auth::user();
if ($user->profil->intitule == "administrateur") {
$erreurs = new Collection();
$this->validate($request, ['intitule' => 'required']);
$profils = Profil::all();
$profil = Profil::find($id);
foreach ($profils as $p) {
if ($request->input('intitule') != $profil->intitule) {
if ($request->input('intitule') == $p->intitule) {
$erreurs->prepend("Cet intitulé existe déjà !");
break;
}
}
}
$profil->intitule = $request->input('intitule');
if (count($erreurs) > 0) {
return response()->view('profil/update_profil', ['profil' => $profil, 'erreurs' => $erreurs]);
}
$profil->save();
return redirect('admin/profil');
}
return "Vous êtes pas administrateur";
}
开发者ID:ATBTeam,项目名称:optionnelles,代码行数:25,代码来源:ProfilController.php
示例7: 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;
}
开发者ID:alerj,项目名称:parlamentojuvenil,代码行数:26,代码来源:Training.php
示例8: getRawCollectionData
private function getRawCollectionData(Collection $collection)
{
foreach ($collection as $element) {
$this->execute_with_relations ? $element->loadDisplayableRelations() : null;
}
return $collection->toArray();
}
开发者ID:martinsv,项目名称:JsonApi,代码行数:7,代码来源:DataHandler.php
示例9: upload
public function upload(PhotoUploadRequest $request)
{
$user = Auth::user();
$destinationPath = 'uploads/';
if ($request->hasFile('files')) {
$photos = new Collection();
$i = 0;
foreach ($request->file('files') as $file) {
$extension = $file->getClientOriginalExtension();
$new_filename = time() . uniqid() . str_random(rand(5, 15)) . '.' . $extension;
$file->move($destinationPath, $new_filename);
$photos[$i] = new Photo();
$photos[$i]->content_type = $file->getClientMimeType();
$photos[$i]->disk_name = $new_filename;
$photos[$i]->file_name = $file->getClientOriginalName();
$photos[$i]->path = $destinationPath . $new_filename;
$photos[$i]->file_size = $file->getClientSize();
$photos[$i]->user_id = $user->id;
$photos[$i]->save();
$i++;
}
return $photos->first();
}
return response()->json(['status' => 'error']);
}
开发者ID:devillom,项目名称:simpleshop,代码行数:25,代码来源:PhotoController.php
示例10: transformCollection
/**
* @param $items
* @return array
*/
public function transformCollection(Collection $items, $showHref = false)
{
$data = $items->map(function ($item) use($showHref) {
return $this->transform($item, $showHref);
})->toArray();
return $data;
}
开发者ID:kchunterdeluxe,项目名称:AutioBackend,代码行数:11,代码来源:Transformer.php
示例11: createData
/**
* @param Collection $model
* @param string $single
*
* @return string
*/
public function createData($model, string $single)
{
$str = sprintf("\n\t\t\$scope.%s = new Minute.Models.%sArray(null);\n", $single, $this->fixName($single));
$str .= sprintf("\t\t\$scope.%s.load(%s);\n", $single, json_encode($model->toArray(), JSON_PRETTY_PRINT));
//{metadata: {offset: 0, limit: 2, total: %d}, items: %s}
return $str;
}
开发者ID:minutephp,项目名称:framework,代码行数:13,代码来源:ModelJs.php
示例12: 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, "[email protected]");
}
}
开发者ID:sagaciresearch,项目名称:adtracking,代码行数:33,代码来源:GenerateTrackings.php
示例13: index
public function index()
{
$sections = Section::all();
if (Auth::user()) {
$cart = Auth::user()->cart;
} else {
$cart = new Collection();
if (Session::has('cart')) {
foreach (Session::get('cart') as $item) {
$elem = new Cart();
$elem->product_id = $item['product_id'];
$elem->amount = $item['qty'];
if (isset($item['options'])) {
$elem->options = $item['options'];
}
$cart->add($elem);
}
}
}
$total = 0;
$options = new Collection();
foreach ($cart as $item) {
$total += $item->product->price * $item->amount;
if ($item->options) {
$values = explode(',', $item->options);
foreach ($values as $value) {
$options->add(OptionValue::find($value));
}
}
}
return view('site.cart', compact('sections', 'total', 'cart', 'options'));
}
开发者ID:omasterdesign,项目名称:omasterdefault,代码行数:32,代码来源:CartController.php
示例14: updateArrangement
public static function updateArrangement(Collection $collection, array $arrangement)
{
$order = 0;
foreach ($arrangement as $parent) {
/** @var \CipeMotion\Medialibrary\Entities\Category $category */
$category = $collection->find(array_get($parent, 'id', 0));
$children = array_get($parent, 'children', []);
if (!is_null($category)) {
$category->order = $order;
$category->parent_id = null;
$category->save();
if (count($children) > 0) {
$childOrder = 0;
foreach ($children as $child) {
/** @var \CipeMotion\Medialibrary\Entities\Category $childCategory */
$childCategory = $collection->find(array_get($child, 'id', 0));
if (!is_null($childCategory)) {
$childCategory->order = $childOrder;
$childCategory->parent_id = $category->id;
$childCategory->save();
$childOrder++;
}
}
}
$order++;
}
}
}
开发者ID:cipemotion,项目名称:medialibrary,代码行数:28,代码来源:Category.php
示例15: 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'));
}
}
开发者ID:JoinTheFlocc,项目名称:flocc-web,代码行数:32,代码来源:ProfilesController.php
示例16: it_additems
/**
* Countable in cart.
*/
public function it_additems(ItemInterface $item, ItemInterface $item2)
{
$collection = new Collection();
$collection->add($item);
$collection->add($item2);
$this->addItems($collection)->shouldHaveCount(4);
}
开发者ID:Symfomany,项目名称:laravelcinema,代码行数:10,代码来源:CartSpec.php
示例17: cachePosts
/**
*
* Cache posts if caching is enabled
*
* @param Collection $posts
*/
protected function cachePosts($posts)
{
$cache = $this->property('cacheLifetime');
if ($cache) {
Cache::put('blogarchive_random_posts', $posts->toArray(), $cache);
}
}
开发者ID:graker,项目名称:blogarchive,代码行数:13,代码来源:RandomPosts.php
示例18: cachePhotos
/**
*
* Cache photos if caching is enabled
*
* @param Collection $photos
*/
protected function cachePhotos($photos)
{
$cache = $this->property('cacheLifetime');
if ($cache) {
Cache::put('photoalbums_random_photos', $photos->toArray(), $cache);
}
}
开发者ID:graker,项目名称:photoalbums,代码行数:13,代码来源:RandomPhotos.php
示例19: createMultiple
/**
* Create a collection of instances of the given model and persist them to the database.
*
* @param integer $total
* @param array $customValues
*
* @return \Illuminate\Database\Eloquent\Collection
*/
public function createMultiple($total, array $customValues = array())
{
$collection = new Collection();
for ($i = 1; $i <= $total; $i++) {
$collection->add($this->create($customValues));
}
return $collection;
}
开发者ID:clemir,项目名称:seeder,代码行数:16,代码来源:Seeder.php
示例20: collectionAsItem
public static function collectionAsItem(Collection $collection, array $columns, $cache = null)
{
$output = [];
foreach ($collection->toArray() as $row) {
$output[] = ['value' => isset($columns['value']) ? $row[$columns['value']] : $row['id'], 'text' => $row[$columns['text']]];
}
return $output;
}
开发者ID:stanmay,项目名称:unflare,代码行数:8,代码来源:Database.php
注:本文中的Illuminate\Database\Eloquent\Collection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论