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


PHP Collection::add方法代码示例

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


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

示例1: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['consultaImeis' => 'required']);
     $imeis = explode("\r\n", $request->get('consultaImeis'));
     $completeUnits = new Collection();
     foreach ($imeis as $imei) {
         $unidad = TrazabilidadMotorola::where('Codigo', $imei)->get();
         $old = false;
         if ($unidad->isEmpty()) {
             $unidad = TrazabilidadOld::where('Codigo', $imei)->get();
             $old = true;
         }
         if (!$unidad->isEmpty() && $imei != '') {
             $puesto = Puesto::where(['Nombre' => 'CFC', 'ConfigLinea_id' => $unidad->first()->ConfigLinea_id])->get();
             $codigoPuestos = CodigoPuesto::where('Puesto_id', $puesto->first()->Id)->get();
             $modeloInfo = ModeloInfo::where(['ConfigLinea_id' => $unidad->first()->ConfigLinea_id])->get();
             $codigoPuestoSimLock = $this->findInCollection($codigoPuestos, 'Nombre', 'sim_lock_nkey');
             if ($codigoPuestoSimLock != null) {
                 if ($old) {
                     $trazabilidadUnidad = TrazabilidadOld::where(['Unidad_id' => $unidad->first()->Unidad_id, 'CodigoPuesto_id' => $codigoPuestoSimLock->Id])->get();
                 } else {
                     $trazabilidadUnidad = TrazabilidadMotorola::where(['Unidad_id' => $unidad->first()->Unidad_id, 'CodigoPuesto_id' => $codigoPuestoSimLock->Id])->get();
                 }
                 $completeUnits->add($this->setUnitsCollection($imei, $trazabilidadUnidad, $modeloInfo));
             } else {
                 $completeUnits->add($this->setUnitsCollection($imei));
             }
         } elseif ($imei != '') {
             $completeUnits->add($this->setUnitsCollection($imei));
         }
     }
     return view('pages.sl_results', ['units' => $completeUnits]);
 }
开发者ID:julioalpa,项目名称:MotorolaSL,代码行数:39,代码来源:HomeController.php

示例2: 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

示例3: getIntialsStates

 public static function getIntialsStates()
 {
     $estados = new Collection();
     $estadoInicial = new Estado();
     $estadoInicial->nombreEstado = "Abierto";
     $estadoInicial->tipoEstado = 1;
     $estadoFinal = new Estado();
     $estadoFinal->nombreEstado = "Cerrado";
     $estadoFinal->tipoEstado = 2;
     $estados->add($estadoInicial);
     $estados->add($estadoFinal);
     return $estados;
 }
开发者ID:inkstudiocompany,项目名称:mastertk,代码行数:13,代码来源:TipoItemController.php

示例4: 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

示例5: 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

示例6: hasPermission

 /**
  * So here's the deal with permissions... Suppose we have code
  * like the following:
  * 
  * @if( $user->hasPermission('edit', 'Employee') )
  *     <li><a href="/editEmployees">Edit Employees</a></li>
  * @endif
  * 
  * Now suppose a user can edit a SUBSET of employees... We still
  * want to display this button, but within this button we need
  * to limit the employees shown. So we need two different actions:
  * 
  *     can you edit ANYTHING?
  *     what can you edit?
  * 
  * To prevent "what can you edit" from returning the entire
  * database in the event that you actually can edit everything,
  * it needs to somehow be condensed. Maybe a query string?
  * 
  * 
  * 
  */
 public function hasPermission($action, $model)
 {
     // First, is $model an instance? If so, get the class name
     if (is_string($model)) {
         $modelName = $model;
         $modelInstance = null;
     } else {
         $modelName = get_class($model);
         $modelInstance = $model;
     }
     // Now get ALL permissions for this action on this model
     $permissions = Permission::where(function ($query) use($action) {
         $query->orWhere('action', $action)->orWhere('action', 'all');
     })->where(function ($query) use($modelName) {
         $query->orWhere('model', 'like', $modelName)->orWhere('model', '*');
     })->get();
     // Now see if we have a matching role
     // To start, see if we have a previously cached list of roles:
     if ($this->roleParents == null) {
         // We start with a list of this user's roles...
         $this->roleParents = $this->roles;
         // Then we iteratively get all parents
         foreach ($this->roleParents as $role) {
             if ($role->parent != null) {
                 $this->roleParents->add($role->parent);
             }
         }
     }
     if ($this->roleChildren == null) {
         // We start with a list of this user's roles...
         $this->roleChildren = $this->roles;
         // Then we need to recursively get all children
         $children = new Collection();
         foreach ($this->roles as $role) {
             $this->roleChildren = $this->roleChildren->merge($this->getAllChildren($role));
         }
         $this->roleChildren = $this->roleChildren->unique();
     }
     foreach ($permissions as $permission) {
         if ($permission->role_id == 0 || $this->roleParents->contains($permission->role) || $this->roleChildren->contains($permission->role) && $permission->trickle) {
             // So the user has a role that can perform the action on this model
             if ($modelInstance == null) {
                 // If we're looking at the model as a whole, we good
                 return true;
             } else {
                 // If we're looking at a specific model, we need to check the domain
                 $domain = json_decode($permission->domain);
                 if (is_array($domain)) {
                     if ($this->confirmDomain($domain, $modelInstance)) {
                         return true;
                     }
                 } else {
                     return true;
                 }
             }
         }
     }
     // Failed to find a valid permission
     return false;
 }
开发者ID:stevendesu,项目名称:reedsmetals.com,代码行数:82,代码来源:User.php

示例7: 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

示例8: getTagsAttribute

 /**
  * Return collection of tags related to the tagged model
  * TODO : I'm sure there is a faster way to build this, but
  * If anyone knows how to do that, me love you long time.
  *
  * @return Illuminate\Database\Eloquent\Collection
  */
 public function getTagsAttribute()
 {
     $tags = new Collection();
     foreach ($this->tagged as $tagged) {
         $tags->add($tagged->tag);
     }
     return $tags;
 }
开发者ID:sushilcs111,项目名称:td,代码行数:15,代码来源:Taggable.php

示例9: getAll

 public function getAll()
 {
     $collection = new Collection();
     foreach ($this->readData() as $article) {
         $collection->add(new Article($article));
     }
     return $collection;
 }
开发者ID:alerj,项目名称:parlamentojuvenil,代码行数:8,代码来源:Service.php

示例10: parents

 public function parents()
 {
     $parents = new Collection();
     $parent = $this;
     while ($parent = $parent->parent) {
         $parents->add($parent);
     }
     return $parents;
 }
开发者ID:fuzzyma,项目名称:contao-eloquent-bundle,代码行数:9,代码来源:Page.php

示例11: stateAds

 public function stateAds(Emirate $emirate, CategoryRepository $categoryRepository)
 {
     //        return $emirate->advertisements->count();
     $products = new Collection();
     foreach ($emirate->advertisements as $ad) {
         $products->add($ad->product);
     }
     return view('pages.search', ['products' => $products, 'categories' => $categoryRepository->getFilterCats()]);
 }
开发者ID:bluecipherz,项目名称:gl-ct,代码行数:9,代码来源:AdvertisementController.php

示例12: seedRandomTags

 public function seedRandomTags($amount = 10)
 {
     $tags = new Collection();
     for ($i = 0; $i < $amount; ++$i) {
         $tag = app()->make(TagRepository::class)->findByNameOrCreate($this->faker->words(2, true));
         $tags->add($tag);
     }
     return $tags;
 }
开发者ID:bjrnblm,项目名称:blender,代码行数:9,代码来源:TagSeeder.php

示例13: getTemplateEntries

 /**
  * Get names of jobtypes, which belongs to the schedule.
  *
  * @return string[] $jobNames
  */
 public function getTemplateEntries()
 {
     $jobNames = new Collection();
     $entries = $this->getEntries()->get();
     foreach ($entries as $entry) {
         $jobNames->add($entry->getJobType->jbtyp_title);
     }
     return $jobNames;
 }
开发者ID:gitter-badger,项目名称:lara-vedst,代码行数:14,代码来源:Schedule.php

示例14: seedRandomTags

 public function seedRandomTags($amount = 10)
 {
     $tags = new Collection();
     for ($i = 0; $i < $amount; ++$i) {
         $tag = Tag::findByNameOrCreate($this->faker->words(2, true), TagType::NEWS_TAG());
         $tags->add($tag);
     }
     return $tags;
 }
开发者ID:vanslambrouckd,项目名称:blender,代码行数:9,代码来源:TagSeeder.php

示例15: haveSections

 public function haveSections($num = 10)
 {
     $faker = Faker::create();
     $sections = new Collection();
     for ($i = 0; $i < $num; $i++) {
         $name = $faker->unique()->sentence(2);
         $sections->add($this->sectionRepo->create(['name' => $name, 'slug_url' => \Str::slug($name), 'type' => $faker->randomElement(['page', 'blog']), 'menu_order' => rand(1, 10), 'menu' => rand(0, 1), 'published' => rand(0, 1)]));
     }
     return $sections;
 }
开发者ID:heroseven,项目名称:cms,代码行数:10,代码来源:SectionsSeeder.php


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