我正在 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 且主体为空。我确实知道我的数据库中有与我的查询匹配的数据。
试试这个
public function getAllJobs()
{
$offres = Offre::where('type', 'job')->get();
return $offres;
}
`