本文整理汇总了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();
});
}
示例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]);
}
}