gpt4 book ai didi

php - Laravel:路线 [登录名] 未定义

转载 作者:可可西里 更新时间:2023-11-01 13:12:59 26 4
gpt4 key购买 nike

我正在 Laravela 中创建一个应用程序,当我尝试访问我的 url 时,例如:http://example.com它返回这个奇怪的错误?这仅在我不访问/login 时发生?

InvalidArgumentException in UrlGenerator.php line 304:
Route [login] not defined.

代码:

use App\Http\Controllers\Frontend;

Route::group(['domain' => 'localhost', 'namespace' => 'Frontend'], function() {

Route::group(['middleware' => 'guest', 'namespace' => 'Guest'], function() {
Route::get('/', function() { return Redirect::to('/login'); });
Route::get('/login', 'LoginController@getView');
Route::post('/login', 'LoginController@onPost');
});

Route::group(['middleware' => 'auth', 'namespace' => 'User'], function() {
Route::get('/', function() { return Redirect::to('/home'); });
Route::get('/home', 'HomeController@getView');
Route::get('/logout', 'LogoutController@performLogout');
});
});

Route::group(['domain' => 'admin.localhost'], function() {
Route::get('/', function() {
return 'Housekeeping will be making an appearance soon!';
});
});

这是我的登录 Controller :

<?php
namespace App\Http\Controllers\Frontend\Guest;

use Auth;
use App\User;
use App\Http\Controllers\Controller;
use Validator;
use Redirect;
use Illuminate\Http\Request;
use App\Database\Frontend\User\Player;
use App\Database\Frontend\WebsiteLogin;

class LoginController extends Controller
{
public function getView()
{
return view('frontend.login');
}

public function onPost(Request $request)
{
$validator = Validator::make($request->all(), [
'mail' => 'required|email|exists:users',
'password' => 'required'
]);

if ( $validator->fails()) {
return Redirect::to('/login')->withErrors($validator->messages());
}
else {
if (!Auth::attempt(['mail' => $request->input('mail'), 'password' => $request->input('password')])) {
$this->addNewWebsiteLogin($request, Player::where('mail', $request->input('mail'))->pluck('id')->first(), "0");
return Redirect::to('/login')->withMessage('Email and password do not match')->withColor('danger');
}
else {
$this->addNewWebsiteLogin($request, Auth::user()->id, "1");

$user = Auth::user();
$user->last_online = time();
$user->save();

/*if (config('frontend.government_only') && (Auth::Guest() || Auth::user()->roleplay->government_id == 0)) {
Auth::logout();
return Redirect::to('/login')->withMessage(config('frontend.site_name') . ' is only open to government individuals at this moment, too bad.')->withColor('danger');
}*/

return Redirect::to('/home')->withMessage('Welcome back!');
}
}
}

private function addNewWebsiteLogin(Request $request, $userId, $status) {
$websiteLogin = new WebsiteLogin;
$websiteLogin->user_id = $userId;
$websiteLogin->request_ip = $request->ip();
$websiteLogin->request_system = 'TODO';
$websiteLogin->request_browser = 'TODO';
$websiteLogin->login_status = $status;
$websiteLogin->save();
}
}

最佳答案

看起来您正在使用 route('login') 创建指向登录页面或表单的链接。

如果您在链接中使用它,只需命名 get() 路由:

Route::get('login', ['as' => 'login', 'uses' => 'LoginController@getView']);

如果您在表单中使用 route() 助手,请为 post() 路由执行此操作。

关于php - Laravel:路线 [登录名] 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43052410/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com