因此,我试图附加一个来自MYSQL DB的充满信息的对象,但结果并不是我所期望的。
控制器-
public function index()
{
$location = Location::orderBy('created_at', 'desc');
return view('location')->with('locations', $location);
}
模型-
class Location extends Model
{
// Primary Key
public $primaryKey = 'id';
// Timestamps
public $timestamps = true;
}
结果-
Builder {#486 ▼
#query: Builder {#485 ▶}
#model: Location {#484 ▶}
#eagerLoad: []
#localMacros: []
#onDelete: null
#passthru: array:12 [▶]
#scopes: []
#removedScopes: []
}
发布于 2018-06-10 00:29:21
改变这一点
$location = Location::orderBy('created_at', 'desc');
至
$location = Location::orderBy('created_at', 'desc')->get();
https://stackoverflow.com/questions/50776167
复制相似问题