سلام وقت بخیر
زمانی که پروژه لاراول ساختم هیچ تغیری در migration user ایجاد نکردم. خواستم که authentication راه اندازی کنم با دستور composer ایجاد کردم و فایل های کنترلر auth ایجاد شد ولی حالاکه فرم ثبت نام رو تو آدرس بار بالا سرچ میکنم ، فرم کامل باز میشه ولی وقتی save میزنم این خطا رو بهم میده
کد های کنترلر register
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\Models\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;
/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:2'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\Models\User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
}
کدهای مدل user
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
کد web.php
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
کدview register
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>register</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body dir="rtl" style="text-align: right">
@include('layouts.topmenu')
<div class="container">
@include('layouts.messages')
<div class="d-flex justify-content-center">
<form action="{{route('register')}}" method="POST">
@include('layouts.messages')
@csrf
<div class="form-group">
<label for="title">last name & first name: </label>
<input type="text" class="form-control @error('name') is-invalid @enderror" name="name">
@error('name')
<div class="alert alert-danger"> {{$message}}</div>
@enderror
</div>
<div class="form-group">
<label for="title">email: </label>
<input type="email" class="form-control @error('email') is-invalid @enderror" name="email">
@error('email')
<div class="alert alert-danger"> {{$message}}</div>
@enderror
</div>
<div class="form-group">
<label for="title"> password </label>
<input type="password" class="form-control @error('password') is-invalid @enderror" name="password">
@error('password')
<div class="alert alert-danger"> {{$message}}</div>
@enderror
</div>
<div class="form-group">
<label for="title"> verify password: </label>
<input type="password" class="form-control @error('password_confirmation') is-invalid @enderror" name="password_confirmation">
@error('password_confirmation')
<div class="alert alert-danger"> {{$message}}</div>
@enderror
</div>
<div class="form-group">
<label for="title"></label>
<button type="submit" class="btn btn-success">register</button>
</div>
</form>
</div>
</div>
</body>
</html>
خطایی که موقع زدن save میده
Illuminate\Database\QueryException
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known. (SQL: select count(*) as aggregate from `users` where `email` = mahdiabolghasemi83@gmail.com)