我正在尝试为我的应用程序创建一个API,以便我可以共享端点并将一个应用程序作为具有业务逻辑的核心应用程序,另一个可以与暴露的端点连接以将该功能用作服务.
我尝试命中端点时收到错误.
下面是我的路线/ 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());
});
Run Code Online (Sandbox Code Playgroud)
我的资源类看起来像
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,
];
}
Run Code Online (Sandbox Code Playgroud)
错误是
Sorry, the page you are looking for could not be found.
我想从我的控制器函数返回两个变量.这样做的目的是在我的index.blade.php表单中使用它们.
public function index()
{
$checkauth=Auth::check();
$postl= PostModell::orderby('created_at','desc')->paginate(4);
return view ('posts.index')->with('postl',$postl);
}
Run Code Online (Sandbox Code Playgroud)
从上面的示例代码中,两个变量是$checkauth
和$postl