當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。