我有2个表:选项和选项选项。 以下是模型:
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管理员中创建关系,就像我之前做过很多次一样,我不明白为什么我会收到错误:你提供的'choice'关系字段optionselections不是提供的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!';
}
为什么我收到错误?
答案 0 :(得分:0)
缺少关系方法内部的返回。关闭