✅ View:
---------------------------------
✅ css:
----------------------------------
#loader {
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
background: rgba(0,0,0,0.75) url(loading.gif) no-repeat center center;
z-index: 10000;
}
✅ Controller:
----------------------------------
public function send_email(Request $request)
{
$validator = \Validator::make($request->all(),[
'email' => 'required|email'
]);
if(!$validator->passes()) {
return response()->json(['code'=>0,'error_message'=>$validator->errors()->toArray()]);
} else {
$token = hash('sha256', time());
$obj = new Subscriber();
$obj->email = $request->email;
$obj->token = $token;
$obj->status = 0;
$obj->save();
$verification_link = url('subscriber/verify/'.$request->email.'/'.$token);
// Send email
$subject = 'Subscriber Verification';
$message = 'Please click on the link below to confirm subscription:
';
$message .= '';
$message .= $verification_link;
$message .= '';
\Mail::to($request->email)->send(new Websitemail($subject,$message));
return response()->json(['code'=>1,'success_message'=>'Please check your email to confirm subscription']);
}
}
public function verify($email,$token)
{
$subscriber_data = Subscriber::where('email',$email)->where('token',$token)->first();
if($subscriber_data) {
$subscriber_data->token = '';
$subscriber_data->status = 1;
$subscriber_data->update();
return redirect()->route('home')->with('success', 'Your subscription is verified successfully!');
} else {
return redirect()->route('home');
}
}
✅ web.php:
----------------------------------
Route::post('/subscriber/send-email', [SubscriberController::class, 'send_email'])->name('subscriber_send_email');
Route::get('/subscriber/verify/{email}/{token}', [SubscriberController::class, 'verify'])->name('subscriber_verify');