Eloquent'in başka bir ön kabulü de her tablonun id adında bir primer key sütunu olduğudur. Bu kuralı aşmak için de bir primaryKey özelliği tanımlamanız gerekecek.
kaynak:
http://laravel.gen.tr/docs/eloquent#basic-usage
standart id kullanımı dışına çıkarsanız muhtemelen hatalarla boğuşursunuz. negatif değer almayan ve her bir kayıtta otomatik olarak n+1 şekilde artan numaralar yılların tecrübeleri ile ortaya çıkmıştır.
uygulama ayarları için veritabanı kullanacaksanız, şuna benzer bir şey yapabilirsiniz:
<?php namespace Muratsplat\mvc\model\Common;
use Exception;
use Muratsplat\mvc\model\Base\BaseModel;
/**
* Description of AppOption
*
* @author Murat Ödünç <murat.asya@gmail.com>
*/
class AppOption extends BaseModel {
/**
* The name of table on database
*
* @var string
*/
protected $table = 'app_options';
/**
* TimeStamps is not needed
*
* @var boolean
*/
public $timestamps = false;
/**
* Guarded attributes
*
* @var array
*/
protected $guarded = array('id');
/**
* To get Option Value
*
* @param string $name the nane of AppOption
* @return string
* @throws Exception
*/
public static function getOption($name) {
$option = AppOption::where('name', '=', $name)->get();
if (count($option) !== 0 ) {
return $option[0]->value;
}
throw new Exception('There is not option that you given on AppOption!');
}
/**
* To set Option value
*
*
* @param string $name
* @param string $value
* @return boolean | void
* @throws Exception
*/
public static function setOption($name, $value) {
$option = AppOption::where('name', $name)->get()->first();
if ($option === null || count($option) === 0 ) {
throw new Exception("There is not option [$name]that you given on AppOption!");
}
$option->value = $value;
return $option->save();
}
}
Singleton tasarımı eklenirse bu model iş görür.