lasthourcloud/routes/api.php

40 lines
1.3 KiB
PHP
Raw Normal View History

2023-03-17 14:33:48 +00:00
<?php
2023-09-25 18:57:52 +00:00
use App\Models\User;
2023-03-17 14:33:48 +00:00
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "api" middleware group. Make something great!
|
*/
2023-04-28 09:06:55 +00:00
Route::get('/health', function () {
return 'OK';
2023-03-17 14:33:48 +00:00
});
2023-09-25 18:57:52 +00:00
Route::middleware(['throttle:5'])->group(function () {
Route::get('/unsubscribe/{token}', function() {
try {
$token = request()->token;
$email = decrypt($token);
if (!User::whereEmail($email)->exists()) {
return redirect('/');
}
if (User::whereEmail($email)->first()->marketing_emails === false) {
return 'You have already unsubscribed from marketing emails.';
}
User::whereEmail($email)->update(['marketing_emails' => false]);
return 'You have been unsubscribed from marketing emails.';
} catch (\Throwable $e) {
return 'Something went wrong. Please try again or contact support.';
}
})->name('unsubscribe.marketing.emails');
});