31 lines
1011 B
PHP
31 lines
1011 B
PHP
<?php
|
|
|
|
use Illuminate\Support\Facades\Route;
|
|
use Paymenter\Extensions\Others\NavbarManager\Models\NavbarLink;
|
|
|
|
// Only register frontend routes, not in admin
|
|
Route::group(['prefix' => 'navbar', 'middleware' => ['web']], function () {
|
|
Route::get('/redirect/{linkId}', function($linkId) {
|
|
try {
|
|
$link = NavbarLink::findOrFail($linkId);
|
|
if (!$link->is_active) {
|
|
abort(404);
|
|
}
|
|
|
|
if ($link->link_type === 'path' && $link->custom_path) {
|
|
return redirect($link->custom_path);
|
|
} elseif ($link->link_type === 'url' && $link->custom_url) {
|
|
return redirect($link->custom_url);
|
|
}
|
|
|
|
abort(404);
|
|
} catch (\Exception $e) {
|
|
\Log::error('NavbarManager: Redirect failed', [
|
|
'link_id' => $linkId,
|
|
'error' => $e->getMessage()
|
|
]);
|
|
abort(404);
|
|
}
|
|
})->name('navbar.redirect');
|
|
});
|