У меня fre sh установка Laravel 7 без composer require laravel / ui
. Моя цель - изменить имя входа по умолчанию на username/email
и password
.
Контроллер AuthController.php
:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Validator,Redirect,Response;
Use App\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Session;
class AuthController extends Controller
{
public function index()
{
return view('login');
}
public function registration()
{
return view('registration');
}
public function getAuthPassword()
{
return 'sms_code';
}
public function postLogin(Request $request)
{
request()->validate([
'id_message' => 'required',
'sms_code' => 'required',
]);
$credentials = $request->only('id_message', 'sms_code');
if (Auth::attempt($credentials)) {
return redirect()->intended('dashboard');
}
return Redirect::to("login");
}
public function postRegistration(Request $request)
{
request()->validate([
'id_message' => 'required',
'sms_code' => 'required|min:6',
'url_attribute' => 'required|min:6',
'mail_from' => 'required',
'mail_to' => 'required',
]);
$data = $request->all();
$check = $this->create($data);
return Redirect::to("dashboard");
}
public function dashboard()
{
if(Auth::check())
{
return view('dashboard');
}
return Redirect::to("login");
}
public function create(array $data)
{
return User::create([
'id_message' => $data['id_message'],
'sms_code' => Hash::make($data['sms_code']),
'url_attribute' => $data['url_attribute'],
'mail_from' => $data['mail_from'],
'mail_to' => $data['mail_to'],
]);
}
public function logout()
{
Session::flush();
Auth::logout();
return Redirect('login');
}
}
Метод App\Http\User.php
<?php
namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use Notifiable;
protected $fillable = [
'mail_from',
'mail_to',
'url_attribute',
'sms_code',
'id_message',
];
protected $hidden = [
'sms_code', 'remember_token',
];
protected $casts = [
];
}
Когда я пытаюсь заполнить форму входа с данными из базы данных -> имя пользователя как id_message
и пароль как sms_code
Вернуть эту ошибку:
ErrorException
Undefined index: password
Illuminate\Foundation\Bootstrap\HandleExceptions::handleError
vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php:156
строка 156 EloquentUserProvider. php ->
public function validateCredentials(UserContract $user, array $credentials)
{
$plain = $credentials['password'];
return $this->hasher->check($plain, $user->getAuthPassword());
}
Я что-то упустил?