I'm doing a API call with bearer token from Flutter mobile app to Laravel backend. After doing a composer update I have this behaviour that unfortunately happens casually, so I don't even know if the composer update was the problem!
Laravel code in the backend:
public function entriesByCase(Cases $case)
{
return EntryResource::collection($case->entries->sortByDesc(self::BEGIN));
}
use App\Media;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class Entry extends JsonResource
{
/**
* Transform the resource into an array.
* @param Request $request
* @return array
*/
public function toArray($request)
{
if (is_null($request)) {
return [];
}
{
return [
'id' => $this->id,
'begin' => $this->begin,
'end' => $this->end,
"inputs" => $this->inputs,
"content" => $this->content,
"comment" => $this->comment,
"case_id" => $this->case_id,
"media_id" => $this->media_id,
"media_name" => Media::where('id', $this->media_id)->first()->name,
"place_id" => $this->place_id,
"communication_partner_id" => $this->communication_partner_id,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}
}
From Valet:
HTTP Requests
-------------
GET /login 200 OK
GET /api/v1/entry/424 302 Found
POST /api/login 200 OK
From Telescope:
{
"x-original-host": "4937-31-19-193-140.eu.ngrok.io",
"x-forwarded-proto": "https",
"x-forwarded-for": "31.19.193.140",
"content-type": "application/json",
"authorization": "********",
"accept-encoding": "gzip",
"accept-charset": "application/json",
"user-agent": "Dart/2.15 (dart:io)",
"host": "4937-31-19-193-140.eu.ngrok.io",
"content-length": "",
"x-forwarded-host": "4937-31-19-193-140.eu.ngrok.io"
}
And for what it counts, this is the Flutter header code:
final token = prefs.getString('token') ?? 0;
final _headers = {
HttpHeaders.authorizationHeader: "Bearer $token",
HttpHeaders.acceptCharsetHeader: "application/json",
'Content-Type': 'application/json'
};
I absolutely don't know why this happens, because it looks it's completely casualš¤·