I'm working on an API with Laravel and I have a problem with my json response, for example I have ina function :
$company = Company::select('name')
->inRandomOrder()
->limit(1)
->get();
return response()->json([
'company' => $company,
]);
With this I get when I call my function :
{
"company": [
{
"name": "Company Number 1"
}
]
}
Why I have an array after company ? "company": [ Is there a way to return directly $company without an object before (named company in my example ?)
Thanks !
firstmethod instead ofget