php - My instance doesn't fetch me the table that I want
问题描述
So I am trying to attach an object full of information from the MYSQL DB, but the outcome isn't what I am expecting.
Controller -
public function index()
{
$location = Location::orderBy('created_at', 'desc');
return view('location')->with('locations', $location);
}
Model -
class Location extends Model
{
// Primary Key
public $primaryKey = 'id';
// Timestamps
public $timestamps = true;
}
Result -
Builder {#486 ▼
#query: Builder {#485 ▶}
#model: Location {#484 ▶}
#eagerLoad: []
#localMacros: []
#onDelete: null
#passthru: array:12 [▶]
#scopes: []
#removedScopes: []
}
解决方案
改变这个
$location = Location::orderBy('created_at', 'desc');
至
$location = Location::orderBy('created_at', 'desc')->get();
推荐阅读
- python - 在 Python 中需要一些帮助
- c# - ml.net 从字符串而不是文件训练模型输入
- python - 如何使用烧瓶/uwsgi/nginx 服务器管理内容和 python 代码?
- javascript - 关注/取消关注以记住按钮的点击。刷新后不工作
- arangodb - 在 COLLECT 中使用 groupsVariable 来跟踪唯一值
- image-processing - 图像处理中的高阶拉普拉斯核
- c# - 无法使用 c# .net 与 Azure MySQL 连接
- python - 为什么我必须将命名元组的 python 双端队列实例化为列表?
- vba - 检查一行中的单元格值是否超过某个值
- java - 如何在 jBPM 中为任务添加超时