gpt4 book ai didi

php - 如何将mysql连接到laravel?

转载 作者:行者123 更新时间:2023-11-29 06:47:06 24 4
gpt4 key购买 nike

显示以下错误

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test1.users' doesn't exist (SQL: select * from users where userName = admin limit 1)

但是我认为我没有名为users的表,我的表名称是login

这是我的登录 Controller 代码

<?php 
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Input;
use App\Login;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller {
public function index(){
return view('login/login');
}
public function show(){
return view('login/login');
}

public function login(){
$uname = Input::get('username');
$pwd = Input::get('password');
// echo "$uname";
// echo "$pwd";
if (Auth::attempt(array('userName' => $uname, 'password' => $pwd))){
return Redirect::to('home');

}
else {
return Redirect::to('login');
}
}
}

我的.env如下

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:Zm3uZ82dtjozo68rs2cGAlXXmzj9EuueqCcKsC73VTo=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=test1
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

最佳答案

but here is the think is i don't have a table named as users my table name is login

如果您的用户表名称是login,请更新/app/下的User.php并更新用户模型以使用'login'表

protected $table = 'login';

关于php - 如何将mysql连接到laravel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48890542/

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