本文整理汇总了PHP中Setting::firstOrNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Setting::firstOrNew方法的具体用法?PHP Setting::firstOrNew怎么用?PHP Setting::firstOrNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Setting
的用法示例。
在下文中一共展示了Setting::firstOrNew方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: makeUpdate
public static function makeUpdate($setting, $value = '', $userId = '')
{
$model = Setting::firstOrNew(array('settings_name' => $setting));
$model->settings_value = $value;
$model->settings_updateby = $userId;
$model->save();
}
示例2: set
public static function set($key, $value)
{
$setting = Setting::firstOrNew(['key' => $key]);
$setting->key = $key;
$setting->value = $value;
Cache::put($key, $value, self::$expireTime);
return $setting->save();
}
示例3: scopeKey
public function scopeKey($query, $key)
{
if (count(Setting::where('key', '=', $key)->get()) == 0) {
$setting = Setting::firstOrNew(['key' => $key]);
$setting->value = '';
$setting->save();
}
return $query->where('key', '=', $key);
}
示例4: settings_post
public function settings_post()
{
$inputs = Input::all();
if (Input::hasFile('plugin')) {
$file = Input::file('plugin');
$name = time() . '-' . Str::slug($file->getClientOriginalName()) . "." . $file->getClientOriginalExtension();
$moved = $file->move(public_path() . '/uploads/plugins/', $name);
$plugin = Setting::firstOrNew(['key' => 'plugin_zip']);
$plugin->value = $name;
$plugin->save();
$pluginPath = Setting::firstOrNew(['key' => 'plugin_zip_path']);
$pluginPath->value = public_path() . '/uploads/plugins/' . $name;
$pluginPath->save();
}
foreach ($inputs as $key => $value) {
$setting = Setting::firstOrNew(['key' => $key]);
$setting->value = $value;
$setting->save();
}
return Redirect::to('/settings')->with('alert', ['type' => 'success', 'message' => 'Configuración guardada.']);
}
示例5: update
/**
* Update a setting value.
*
* @param string $key The setting key
* @param mixed $value The setting value
*
* @return boolean
*
* @throws \Subbly\Api\Service\Exception If the setting key does not exists
* @throws \Subbly\Api\Service\Exception If the setting value has not the good format
*
* @api
*/
public function update($key, $value)
{
if ($this->fireEvent('updating', array($key, $value)) === false) {
return false;
}
if (!is_string($key) || !$this->has($key)) {
throw new Exception(sprintf(Exception::STATS_KEY_NOT_EXISTS, $key));
}
$default = $this->defaults($key);
if (isset($default['type']) && gettype($value) !== $default['type']) {
throw new Exception(sprintf(Exception::STATS_VALUE_WRONG_TYPE, json_encode($value), $key, $default['type']));
}
$stats = $this->getCachedStats();
// TODO identifier = PACKAGE_NAME.KEY_NAME
// Example subbly.shop_name
$setting = Setting::firstOrNew(array('identifier' => $key, 'plugin_identifier' => ''));
$setting->value = $value;
$setting->setCaller($this);
$setting->save();
$stats->offsetSet($key, $value);
$this->setCachedStats($stats);
$this->fireEvent('updated', array($key, $value));
return true;
}