Added middleware IsWebsiteTranslations and IsProject.

This fixes errors where Project or WebsiteTranslations are not found.
This commit is contained in:
Leonid Nikitin 2024-05-03 00:06:59 +05:00
parent 478cbe4762
commit 156d8a9f68
Signed by: kor-elf
GPG Key ID: 3C0F720C170F6E1D
3 changed files with 59 additions and 7 deletions

View File

@ -0,0 +1,25 @@
<?php declare(strict_types=1);
namespace App\Http\Middleware;
use App\Models\Project;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
final class IsProject
{
public function handle(Request $request, \Closure $next): Response
{
$project = $request->get('project');
if (\is_null($project)) {
\abort(Response::HTTP_NOT_FOUND);
}
if ($project instanceof Project === false) {
\report("$project must be an instance of Project");
\abort(Response::HTTP_NOT_FOUND);
}
return $next($request);
}
}

View File

@ -0,0 +1,25 @@
<?php declare(strict_types=1);
namespace App\Http\Middleware;
use App\Services\WebsiteTranslations;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
final class IsWebsiteTranslations
{
public function handle(Request $request, \Closure $next): Response
{
$websiteTranslations = $request->get('websiteTranslations');
if (\is_null($websiteTranslations)) {
\abort(Response::HTTP_NOT_FOUND);
}
if ($websiteTranslations instanceof WebsiteTranslations === false) {
\report("$websiteTranslations must be an instance of WebsiteTranslations");
\abort(Response::HTTP_NOT_FOUND);
}
return $next($request);
}
}

View File

@ -3,11 +3,13 @@
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
Route::get('/', [\App\Http\Controllers\Site\ProjectsController::class, 'index'])->name('home'); Route::get('/', [\App\Http\Controllers\Site\ProjectsController::class, 'index'])->name('home');
Route::middleware([\App\Http\Middleware\IsProject::class, \App\Http\Middleware\IsWebsiteTranslations::class])->group(function () {
Route::get('/language/{language}', [\App\Http\Controllers\Site\ProjectsController::class, 'index'])->name('home-language'); Route::get('/language/{language}', [\App\Http\Controllers\Site\ProjectsController::class, 'index'])->name('home-language');
Route::get('feedback', [\App\Http\Controllers\Site\FeedbackController::class, 'index'])->name('feedback'); Route::prefix('feedback')->group(function () {
Route::get('feedback/language/{language}', [\App\Http\Controllers\Site\FeedbackController::class, 'index'])->name('feedback-language'); Route::get('/', [\App\Http\Controllers\Site\FeedbackController::class, 'index'])->name('feedback');
Route::get('feedback/success', [\App\Http\Controllers\Site\FeedbackController::class, 'index'])->name('feedback.success'); Route::get('language/{language}', [\App\Http\Controllers\Site\FeedbackController::class, 'index'])->name('feedback-language');
Route::get('feedback/success/language/{language}', [\App\Http\Controllers\Site\FeedbackController::class, 'index'])->name('feedback.success-language'); Route::post('/', [\App\Http\Controllers\Site\FeedbackController::class, 'send'])->name('feedback.send');
Route::post('feedback', [\App\Http\Controllers\Site\FeedbackController::class, 'send'])->name('feedback.send'); Route::post('language/{language}', [\App\Http\Controllers\Site\FeedbackController::class, 'send'])->name('feedback.send-language');
Route::post('feedback/language/{language}', [\App\Http\Controllers\Site\FeedbackController::class, 'send'])->name('feedback.send-language'); });
});