Laravel picks the wrong table, the users
table. I have switched the table in config/auth
to the correct one but for some reason, Laravel still uses the default users
table.
Code
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
class UserLoginController extends Controller
{
protected $table = 'pupil';
public function showLoginForm()
{
return view('home');
}
public function login(Request $request)
{
$this->validate($request, [
'user' => 'required',
'password' => 'required|min:3'
]);
$user = User::where('accountName', $request->user)
->where('password', $request->password)
->first();
if ($user) {
Auth::login($user);
return redirect()->route('neue_anmeldung');
}
return redirect()->back()->withInput('email');
}
}
I get the following error message.
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'database1.users' doesn't exist (SQL: select * from
users
whereaccountName
= 6001 andpassword
= password limit 1)
Your User
model is configured to use the users
table. You have defined the table in your controller
which is wrong. You need to define the property protected $table = 'pupil';
in your App\User.php