本文整理汇总了PHP中app\Setting::firstOrNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Setting::firstOrNew方法的具体用法?PHP Setting::firstOrNew怎么用?PHP Setting::firstOrNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Setting
的用法示例。
在下文中一共展示了Setting::firstOrNew方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set
/**
* Static method to set a value to the settings table
*/
public static function set($key, $value)
{
$setting = \App\Setting::firstOrNew(['name' => $key]);
$setting->value = $value;
$setting->save();
}
示例2: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$data = $request->all();
$clubs = json_decode($data['clubs'], true);
$country = Country::firstOrNew(['name' => $data['country']]);
$country->save();
$competition = Competition::firstOrNew(['name' => $data['name'], 'country_id' => $country->id, 'type' => $data['type']]);
if ($country->competitions()->where(['id' => $competition->id])->get()->count() == 0) {
$country->competitions()->save($competition);
}
Auth::user()->competitions()->save($competition);
$season = Season::firstOrNew(['name' => $data['season']]);
$season->save();
if ($season->competitions()->where(['id' => $competition->id])->get()->count() == 0) {
$season->competitions()->attach($competition->id);
}
$competition->clubsByName()->wherePivot('season_id', '=', $season->id)->detach();
foreach ($clubs as $club) {
$competition->storeClub($club, $country, $season);
}
$num = count($clubs);
if ($num % 2 != 0) {
$clubs[$num++] = $competition->storeClub(['name' => '//no-name', 'location' => '//no-loc', 'num' => $num], $country, $season);
}
$settings = Setting::firstOrNew(['competition_id' => $competition->id, 'season_id' => $season->id]);
$settings->save();
return $competition->storeCompetition($season, $num);
}