我有两个表:选项和选项选择。以下是型号:
use LaravelBook'Ardent'Ardent;
class Option extends Ardent
{
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'options';
// MASS ASSIGNMENT -------------------------------------------------------
// define which attributes are mass assignable (for security)
// we only want these 1 attribute able to be filled
protected $fillable = array('name');
public function selections()
{
return $this->hasMany('optionselection');
}
}
use LaravelBook'Ardent'Ardent;
class Optionselection extends Ardent
{
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'option_selections';
// MASS ASSIGNMENT -------------------------------------------------------
// define which attributes are mass assignable (for security)
// we only want these 1 attribute able to be filled
protected $fillable = array('option_id', 'name');
public function choice()
{
$this->belongsTo('option');
}
}
我正试图在Laravel管理员中创建关系,就像我以前做过很多次一样,但我不明白为什么会出现错误:您为选项选择提供的"选择"关系字段在提供的Eloquent模型上不是有效的关系方法名
return array(
/**
* Model title
*
* @type string
*/
'title' => 'Option Selections',
/**
* The singular name of your model
*
* @type string
*/
'single' => 'Option Selection',
/**
* The class name of the Eloquent model that this config represents
*
* @type string
*/
'model' => 'optionselection',
/**
* The columns array
*
* @type array
*/
'columns' => array(
'choice' => array(
'title' => 'Option',
'relationship' => 'choice',
'select' => 'name',
),
'selection' => array(
'title' => 'Selection'
),
),
'edit_fields' => array(
'choice' => array(
'title' => 'Option',
'type' => 'relationship',
'name_field' => 'name',
),
'name' => array(
'title' => 'Selection Name',
'limit' => 30,
),
),
'action_permissions'=> array(
),
)
我知道方法/关系字段实际上确实存在,并且在Laravel Administrator之外得到了认可,因为这是有效的:
$optsel = new Optionselection();
// var_dump($svcloc);
if (method_exists($optsel, "choice")) {
echo '<br/>Recognizes!';
} else {
echo '<br/>Problem!';
}
为什么我会出错?
在relationship方法中缺少返回。关闭