0
votes

I have made a registration form in my frontend ( Not a laravel default registration form ) . I have used Laravel Email Verification

I have implements MustVerifyEmail in User Model

But In that custom registraion form in my frontend when i hit submit it redirects the page to /admin/home but email is not been sending when i register but If I click on resend email again it sends the email . I want to fix that Does anyone know how ? Do I have to implements MustVerifyEmail to that controller too or what ?

IGNORE THAT CITY AND ROOM IN THE FUNCTION !!!!!

class QuickRegisterController extends Controller

{

public function quickList(Request $request)
{
  $this->validate($request ,[
    'features' => 'required',
    'rommies' => 'required',
    'price' => 'required',
    'avaiability' => 'required',
    'utility' => 'required',
    'owner_working_email' => 'required',
    'address' => 'required',
    'exact_address' => 'required',
    'owner_of_the_room' => 'required',
  ]);

    $user = User::firstOrCreate([
        'name' => $request->owner_of_the_room,
        'email' => $request->owner_working_email,
        'password' => bcrypt($request->password),
        'role_id' => config('quickadmin.default_role_id'),
    ]);
    \Auth::loginUsingId($user->id);
    if (\Auth::check()) {
        $city = TotalCity::firstOrCreate([
            'name' => $request->city,
            'created_by_id' => \Auth::user()->id,
        ]);

        if ($city) {
            $room = new MyRoom;
        $room->location_id = $city->id;
        $room->features = $request->features;
        $room->rommies = $request->rommies;
        $room->price = $request->price;
        $room->utility = $request->utility;
        $room->avaiability = $request->avaiability;
        $room->owner_woring_email = $request->owner_working_email;
        $room->address = $request->address;
        $room->exact_address = $request->exact_address;
        $room->owner_of_the_room = $request->owner_of_the_room;

        $room->save();
        }

        return redirect('/admin/home');
    }
    else {
        return redirect()->back()->with('Form Submission Failed . Try Again Later');
    }
}

}

1

1 Answers

0
votes

If you look into the RegisterController that Laravel provides with its auth scaffolding, not sure if you are using that or not, it implements the RegistersUsers trait. That trait implements an event that is triggered upon registration. You can use the RegistersUsers trait in your class or create your own custom event.

I'll show you how to use the trait.

At the top of your file:

use Illuminate\Foundation\Auth\RegistersUsers;

Right inside your class:

use RegistersUsers;

For Example:

use Illuminate\Foundation\Auth\RegistersUsers;

class QuickRegisterController extends Controller
{
    use RegistersUsers;

    // ....
}

You'll need to set up the route as well.

// The register method is coming from the trait
Route::post('/register', 'QuickRegisterController@register');

Also,

You'll want to update your method name to create, the trait calls a create method from the implementor, which is where the user gets created and then the event is triggered, and in that create a method just return the new user, instead of redirecting back.

This might not be all you need to do to get this working, but it will get you started. If you are interested in creating your own event:

https://laravel.com/docs/5.8/events

Or, as @Bipin Regmi pointed out you can just use the event that is being used in the trait

event(new \Illuminate\Auth\Events\Registered($user = $this->create($request->all())));