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


PHP Area::firstOrCreate方法代码示例

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


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

示例1: fire

 /**
  * Execute the console command.
  *
  *	@todo  DON'T UPDATE LOCATIONS IF THEY'RE ALREADY SET
  *
  * @return mixed
  */
 public function fire()
 {
     $Bodmin = Area::firstOrCreate(['name' => 'Bodmin']);
     // Ensure current locations are saved.
     foreach (array_unique(Interview::where('location_id', '=', '')->lists('location')) as $location) {
         if (strlen($location) === 0) {
             continue;
             // don't want to clobber real locations
         }
         $L = Location::firstOrNew(['name' => $location]);
         if ($L->exists) {
             continue;
         }
         $L->area()->associate($Bodmin);
         $L->save();
     }
     Interview::all()->each(function ($Interview) {
         $Location = Location::where('name', '=', $Interview->location);
         if ($Location->count() <= 0) {
             \Log::error("This location not found despite having just been confirmed a few lines above", $Interview->toArray());
             return;
         }
         $Interview->location_id = $Location->first()->id;
         $Interview->save();
     });
 }
开发者ID:mymedialab,项目名称:listenings,代码行数:33,代码来源:MigrateLocations.php

示例2: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     $faker = Faker\Factory::create();
     $u = User::firstOrCreate(['username' => 'admin', 'name' => 'The Admin', 'email' => 'admin@example.com', 'is_admin' => true]);
     $u->password = Hash::make('password');
     $u->save();
     $A = Area::firstOrCreate(['name' => 'Bodmin']);
     for ($i = 0; $i < 20; $i++) {
         Location::firstOrCreate(['name' => $faker->streetName, 'area_id' => $A->id]);
     }
 }
开发者ID:mymedialab,项目名称:listenings,代码行数:17,代码来源:DatabaseSeeder.php


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