【发布时间】:2017-12-13 09:41:49
【问题描述】:
所以我对这条路线有一个 Axios 获取请求:
/threads/test/{fooId}/get
这个方法处理的:
public function apiThreadsByTag(Foo $foo)
{
dd($foo);
}
Foo 是一个模型,{id} 确实是正确的。但是,我仍然得到了一个没有任何属性的模型实例:
Foo {#323
#guarded: []
#connection: null
#table: null
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#perPage: 15
+exists: false
+wasRecentlyCreated: false
#attributes: []
#original: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#events: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
}
但是,如果我将方法更改为,它确实会在数据库中找到它:
public function apiThreadsByTag($fooId)
{
dd(Foo::find($fooId));
}
那么,这里有什么问题吗?我非常感谢任何提示!
【问题讨论】:
-
尝试更改 var 的名称,使其与通配符相同。像这样:public function apiThreadsByTag(Foo $fooId) { dd($fooId); }
-
您是否应用了正确的路由模型绑定?
标签: laravel model routes eloquent parameter-passing