Php 您提供的关系字段不是所提供的Eloquent模型上的有效关系方法名称
我有两张表:选项和选项选择。 以下是模型:Php 您提供的关系字段不是所提供的Eloquent模型上的有效关系方法名称,php,laravel,eloquent,Php,Laravel,Eloquent,我有两张表:选项和选项选择。 以下是模型: use LaravelBook\Ardent\Ardent; class Option extends Ardent { /** * The database table used by the model. * * @var string */ protected $table = 'options'; // MASS ASSIGNMENT ---------------------
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 administrator中创建关系,但我不明白为什么会出现错误:您为optionselections提供的“选择”关系字段在所提供的雄辩模型上不是有效的关系方法名称
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(
),
)
我知道method/relationship字段确实存在,并且在Laravel Administrator之外被识别,因为这是有效的:
$optsel = new Optionselection();
// var_dump($svcloc);
if (method_exists($optsel, "choice")) {
echo '<br/>Recognizes!';
} else {
echo '<br/>Problem!';
}
$optsel=newoptionselection();
//var_dump($svcloc);
如果(方法_存在($optsel,“选择”)){
回声'
识别!';
}否则{
回显“
问题!”;
}
为什么会出现错误?在关系方法中缺少返回值。封闭的