Added blog, pages, menu, category
This commit is contained in:
40
app/Http/Middleware/CheckPageSlug.php
Normal file
40
app/Http/Middleware/CheckPageSlug.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class CheckPageSlug
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$slug = $request->route('slug');
|
||||
|
||||
$publicPath = public_path($slug);
|
||||
|
||||
if (file_exists($publicPath) && is_file($publicPath) && pathinfo($slug, PATHINFO_EXTENSION) === 'php') {
|
||||
ob_start();
|
||||
include($publicPath);
|
||||
$content = ob_get_clean();
|
||||
ob_flush();
|
||||
return response($content);
|
||||
}
|
||||
|
||||
if (file_exists($publicPath) && is_file($publicPath)) {
|
||||
return response()->file($publicPath);
|
||||
}
|
||||
|
||||
if (is_dir($publicPath)) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user