0

This is my function :

public function index(Request $request)
{
    $data = User::all();
    return view('data.index',[
        'data' => $data
    ]);
}

I write a test for this

public function testIndex()
{
   $response = $this->call('GET', '/data');

   $this->assertEquals(200, $response->status());
}

but not works. Show redirection

Response status code [302] is not a successful status code.
Failed asserting that false is true.

Here is my route:

Route::group(['prefix' => 'data'], function() {
    Route::get('/', ['as' => 'data.index', 'uses' => 'DataController@index']);
});

I tried everything but still showing the same thing.

1 Answers1

0

You just need to change your index() method as following :

public function index(Request $request)
{
    $data = User::all();
    return view('data.index',[
        'data' => $data
    ])->setStatusCode(200);
}

Hope it will helps you. Thanks

Vishal Ribdiya
  • 840
  • 6
  • 18