我有两个模型公告:
class Announcement extends Eloquent {
public function characteristics() {
$this->hasMany('Characteristic');
}
}
和特点:
class Characteristic extends Eloquent {
protected $guarded = array();
public static $rules = array();
public function announcement() {
return $this->belongsTo('Announcement');
}
}
有两张表:
CREATE TABLE characteristics (
id integer PRIMARY KEY AUTOINCREMENT,
title varchar DEFAULT('Количество'),
announcement_id integer,
count integer DEFAULT('0'),
value_name varchar DEFAULT('шт.'),
created_at datetime,
updated_at datetime,
deleted_at datetime
);
和
CREATE TABLE announcements (
id integer PRIMARY KEY AUTOINCREMENT,
title varchar DEFAULT(''),
description varchar DEFAULT(''),
created_at datetime,
updated_at datetime,
deleted_at datetime
);
它们都带有一些测试数据。
这是我在 routes.php 中的代码:
Route::get('/', function()
{
$test = Announcement::find(1)->characteristics();
var_dump($test);
});
但我总是得到NULL。我无法理解,为什么...