Search code examples
laraveleloquentlaravel-5.3

Call to undefined method Illuminate\View\View::make() laravel 5.3 not redirected to the view


I am trying to redirect after deleting a user from user table.
Everything works fine, but after deleting the user I am not redirected to same page.

This is my AdminController index method

public function index()
{
    //$users = DB::table('users')->get();

    $users = DB::table('users')
        ->where('is_active', 1)
        ->get();


    //return  view('adminpage', ['users' => $users]);
    return View::make('adminpage',['users' => $users]);

}

// delete function in `AdminController`

public function destroy($id)
{
    User::destroy($id);

     return Redirect::to('/admin');
}

here is my route

Route::group(['middleware' => ['admin']], function () {
    Route::get('/admin', 'AdminController@index');
    Route::resource('/deleteuser', 'AdminController');

    Route::get('/adduser', function () {
      return view('adduser');
    });
});

Why am I not redirected to adminpage, If I use simple

//return  view('adminpage', ['users' => $users]);

I only get to go to the view. But then after deleting the record I get below error.

FatalThrowableError in AdminController.php line 105: Class 'App\Http\Controllers\Redirect' not found

When I use

return View::make('adminpage',['users' => $users]);

I can even go to the view,

Why View::make doesn't work, and why am I not redirected to adminpage. Thanks In advance.


Solution

  • Redirect is a facade for a redirect response and therefore needs to be included in the current namespace.

    Add use Redirect alongside your other use declarations, after your namespace declaration.

    Alternatively, you can use the redirect() helper.

    return redirect()->to('/admin');