Laravel API 返回 200 且主体为空

问题描述 投票:0回答:1

我正在 Laravel 中开发 API。我不知道我做错了什么,但它一直返回 200 OK 但没有任何数据。

这是

api.php

Route::get('/offre/jobs', [OffreController::class, 'getAllJobs']); 

这是我的 OfferController :

 //this will only return job type offers
 public function getAllJobs()
 {
     $offres = Offre::where('type', 'job')->get();
     return $offres;
 }

这是我的报价模型:

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Offre extends Model
{
use HasFactory;

protected $fillable = [
    'title',
    'type',
    'employmentType',
    'workplace',
    'description',
     ...
];

每当我尝试使用我的客户端(Thunder)时,它总是返回 200 且主体为空。我确实知道我的数据库中有与我的查询匹配的数据。

laravel
1个回答
0
投票

试试这个

public function getAllJobs()
{
    $offres = Offre::where('type', 'job')->get();
    return $offres;
}

`

© www.soinside.com 2019 - 2024. All rights reserved.