Я пробовал все шаги с этого сайта:
https://vegibit.com/how-to-send-email-to-new-users/
и обнаружил некоторые проблемы в маршруте, "loginUsingId (1 ) " это вызовет идентификатор пользователя 1 из базы данных, и я хочу изменить его с автоматическим приращением. Таким образом, после того, как новый пользователь зарегистрировался и его данные были помещены в базу данных, они будут перенаправлены на эту страницу -> / member и получат уведомление по электронной почте.
$user = \Auth::loginUsingId(1);
Route::get('/member', function () use ($user) {
\Mail::to($user)->send(new welcomeMail($user));
return view('member');
});
Вот мой контроллер регистра. php
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use App\Mail\welcomeMail;
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::MEMBER;
/**
* 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:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'phone' => ['required', 'numeric', 'min:11'],
'asal_instansi' => ['required', 'string'],
'usia' => ['required', 'integer'],
'pekerjaan' => ['required', 'string'],
]);
}
protected $primaryKey = 'id_maganger';
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'phone' => $data['phone'],
'asal_instansi'=> $data['asal_instansi'],
'usia' => $data['usia'],
'pekerjaan' => $data['pekerjaan'],
]);
\Mail::to($user)->send(new welcomeMail($user));
}
}
и вот моя таблица базы данных
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id_maganger');
$table->string('name');
$table->string('email')->unique();
$table->boolean('is_admin')->default(0);
$table->bigInteger('phone');
$table->string('asal_instansi');
$table->bigInteger('usia');
$table->string('pekerjaan');
$table->string('password')->default("");
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
это мое приложение / пользователь. 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;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'asal_instansi', 'usia', 'phone', 'pekerjaan', 'is_admin'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
public function setpasswordAttribute($value)
{
$this->attributes['password'] = ($value ?: str_random(6));
}
protected $hidden = [
'password', 'remember_token',
];
protected $primaryKey = 'id_maganger';
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
Может кто-нибудь помочь мне с этим? Спасибо