@hala can you show the code of the platform method?
Feb 16, 2020
6
Level 3
Agent feature test
I'm doing feature test when i sent Agent user with headers and dd(new agent ()->platform) i got false , i checked the route using postman and it's all looks great how can i fix this issue ?
this is the test
/** @test * */
public function app_version_api_return_404_for_not_exists_versions()
{
$version=create(AppVersion::class);
$response= $this->getJson("api/v1/check-update/{$version->id}/{$version->build}",['User-Agent'=>"Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko; googleweblight) Chrome/38.0.1025.166 Mobile Safari/535.1"]);
$response->assertStatus(200);
}
CONTROLLER
public function index(Request $request)
{
$agent=new Agent();
dd($agent->platform());
$version=AppVersion::findOrFail($request->version_id)->where('platform',$agent->platform());
}
}
platform
public function platform($userAgent = null) { return $this->findDetectionRulesAgainstUA(static::getPlatforms(), $userAgent); }
Level 53
@hala replace $agent=new Agent(); with $agent = app(Agent::class); (or app('agent');), or type-hint as a dependency in your action public function index(Request $request, Agent $agent).
1 like
Please or to participate in this conversation.