找不到使用中间件收益页面重定向到命名路由

时间:2018-09-20 23:53:56

标签: laravel

我的web.php文件中具有以下路由:

Route::get('/', 'PostsController@index')->name('home');
Route::get('/login', 'SessionsController@show');

SessionController类具有一个公共构造函数,该构造函数使用Laravel的中间件来检查用户是否为访客:

namespace App\Http\Controllers;
use Illuminate\Http\Request;

class SessionsController extends Controller
{
    public function __construct() {
        $this->middleware('guest')->except(['destroy']);

    public function create() {

        // Validade form data
        $this->validate(request(), [
            'email' => 'required',
            'password' => 'required'
        ]);

        // Attempt to authenticate the user
        if(! auth()->attempt(request(['email', 'password']))) {
            return back()->withErrors([
                'message' => 'Please check you credentials and try again'
            ]);
        }
        return redirect()->home();
    }
    public function show() {
        return view('login.show');
    }

    public function destroy() {
        auth()->logout();
        return redirect()->home();
        //return redirect()->route('home');
    }
}

发生的事情是,当我登录并尝试访问/login时,我被重定向到home,但是在浏览器中却出现“对不起,找不到页面”。我了解到,中间件在尝试登录时会检查我是否是访客,如果不是,则应将我重定向到推荐页面。

我检查了php artisan route:list,发现/被分配了名称home。我现在没主意了,我将不胜感激。

1 个答案:

答案 0 :(得分:1)

尝试一下

String stars[] = {Elyes Gabel, Katharine McPhee, Robert Patrick}

TextView textView = // initialise the textview here or however you do.

StringBuilder builder = new StringBuilder();
for (String star: stars) {
    builder.append(star);
    builder.append(", ");
}

textView.setText(builder.toString());