Skip to content

Commit 9d45946

Browse files
committed
feat: add wantsJson method
1 parent ef49b82 commit 9d45946

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/Http/Request.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,23 @@ public function isAjax(): bool
424424
return false;
425425
}
426426

427+
public function wantsJson(): bool
428+
{
429+
$accept = $this->getHeader('accept');
430+
431+
if ($accept && str_contains($accept, 'application/json')) {
432+
return true;
433+
}
434+
435+
$content_type = $this->getHeader('content-type');
436+
437+
if ($content_type && str_contains($content_type, 'application/json')) {
438+
return true;
439+
}
440+
441+
return false;
442+
}
443+
427444
/**
428445
* Check if a url matches with the pattern
429446
*

0 commit comments

Comments
 (0)