Answer the question
In order to leave comments, you need to log in
Where do I go wrong when creating authorization in Laravel?
- Laravel 8
- PHP 7.4
- Googled
- I looked at the Doc (previously I worked on the lara and did authorization, but either something new appeared in version 8, or I forget some trifle).
Controller 1 (super.ru/auth):
Receives email, password data and performs authorization.
$result = Auth::Attempt(['password' => 'superpwd', 'email' => '[email protected]'], true);
Auth::check(); // false
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Hash;
class AuthUser extends Controller
{
public function register(Request $request)
{
// return $request->all();
$request->validate([
'name' => 'required|string',
'lastname' => 'required|string',
'secondname' => 'required|string',
'tel' => 'required|numeric',
'password' => 'required|string',
]);
$user = User::create([
'name' => $request->name,
'lastname' => $request->lastname,
'secondname' => $request->secondname,
'tel' => $request->tel,
'password' => Hash::make($request->password),
'email' => '',
]);
$login = Auth::login($user);
return response()->json([
'message' => 'Регистрация прошла успешно!',
'login' => $login
]);
}
public function test(Request $request) {
$result = Auth::Attempt(['password' => 1, 'email' => '[email protected]'], true);
dump($result);
}
public function test2(Request $request) {
$result = Auth::check();
dump($result);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question