Skip to content

Commit b2e2bec

Browse files
authored
Request expects JSON
Improve how to determine if the current request probably expects a JSON response. That following test can be simplified be adapting [`$request->expectsJson()`](https://github.com/laravel/framework/blob/master/src/Illuminate/Http/Concerns/InteractsWithContentTypes.php#L24) ```diff public function test_a_user_can_view_any_users() { $user = User::factory()->create(); - $jsonResponse = $this->actingAs($user) - ->withHeaders([ - 'Accept' => 'application/json', - 'X-Requested-With' => 'XMLHttpRequest', - ]) - ->get(route('users.index')); + $jsonResponse = $this->actingAs($user)->json('GET', route('users.index')); $jsonResponse->assertSuccessful(); $this->assertArrayNotHasKey('error', $jsonResponse->getData(true)); } ```
1 parent ae234f4 commit b2e2bec

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Services/DataTable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ abstract class DataTable implements DataTableButtons
154154
*/
155155
public function render($view, $data = [], $mergeData = [])
156156
{
157-
if ($this->request()->ajax() && $this->request()->wantsJson()) {
157+
if ($this->request()->expectsJson()) {
158158
return app()->call([$this, 'ajax']);
159159
}
160160

0 commit comments

Comments
 (0)