Added middleware IsWebsiteTranslations and IsProject.
This fixes errors where Project or WebsiteTranslations are not found.
This commit is contained in:
parent
478cbe4762
commit
156d8a9f68
25
app/application/app/Http/Middleware/IsProject.php
Normal file
25
app/application/app/Http/Middleware/IsProject.php
Normal 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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -3,11 +3,13 @@
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
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('feedback', [\App\Http\Controllers\Site\FeedbackController::class, 'index'])->name('feedback');
|
||||
Route::get('feedback/language/{language}', [\App\Http\Controllers\Site\FeedbackController::class, 'index'])->name('feedback-language');
|
||||
Route::get('feedback/success', [\App\Http\Controllers\Site\FeedbackController::class, 'index'])->name('feedback.success');
|
||||
Route::get('feedback/success/language/{language}', [\App\Http\Controllers\Site\FeedbackController::class, 'index'])->name('feedback.success-language');
|
||||
Route::post('feedback', [\App\Http\Controllers\Site\FeedbackController::class, 'send'])->name('feedback.send');
|
||||
Route::post('feedback/language/{language}', [\App\Http\Controllers\Site\FeedbackController::class, 'send'])->name('feedback.send-language');
|
||||
Route::prefix('feedback')->group(function () {
|
||||
Route::get('/', [\App\Http\Controllers\Site\FeedbackController::class, 'index'])->name('feedback');
|
||||
Route::get('language/{language}', [\App\Http\Controllers\Site\FeedbackController::class, 'index'])->name('feedback-language');
|
||||
Route::post('/', [\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');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user