简体   繁体   中英

Laravel redirects login page after a delete operation

When I try to destroy a record with resource controller, laravel redirects to login page although I applied auth middleware in the controller.

Laravel Version is 6.x.

Web.php

<?php
Auth::routes();

Route::resource('sliders', 'Admin\SliderController');

SliderController.php

<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Slider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Storage;
use Validator;

class SliderController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }

...other methods

    public function destroy(Slider $slider)
    {
        Slider::destroy($slider->id);

        Session::flush('status', 'success');

        return redirect('sliders');
    }
    }
}

I couldn't understand why it redirects to login page.

Help please

Thanks

Session flush is to delete all data https://laravel.com/docs/master/session#deleting-data

Use

$request->session()->flash('status', 'success');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM