【发布时间】:2018-01-24 07:36:39
【问题描述】:
我正在尝试为我的应用程序创建一个 API,以便我可以共享端点,并让一个应用程序作为具有业务逻辑的核心应用程序,而另一个可以与公开的端点连接以将功能用作服务。
我在尝试到达端点时遇到错误。
下面是我的route/api.php
<?php
use App\PostModell;
use App\Http\Resources\PostModellResource;
use Illuminate\Http\Request;
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
Route::get( '/cars',function(){
return new PostModellResource(PostModell::all());
});
我的资源类看起来像
class PostModellResource extends Resource
{
public function toArray($request)
{
return
[
'id'=>$this->id,
'title'=>$this->title,
'body'=>$this->body,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
错误是
Sorry, the page you are looking for could not be found.
【问题讨论】:
-
您要访问哪个网址??向我们展示您尝试过的带有域名的完整网址,并收到类似
www.google.com/lists的错误 -
这是127.0.0.1:8000/cars的网址
-
@DENNISKITHINJI 因为它在
routes/app.php,你需要使用https://127.0.0.1:8000/api/cars -
@Sohel0415 这工作127.0.0.1:8000/api/cars 但也收到一个新错误“此集合实例上不存在属性 [标题]。”这发生在我所有的模型列上
-
@DENNISKITHINJI 查看我的更新答案
标签: php laravel rest laravel-5 laravel-5.5