Skip to content

Commit

Permalink
Improved readability of code and data collection that is returned (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobWez98 authored Oct 20, 2022
1 parent 18ab816 commit 69d2d1f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
10 changes: 2 additions & 8 deletions routes/fallback.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<?php
use Statamic\Facades\Data;

if ($entry = Statamic\Facades\Entry::findByUri(request()->path())->toResponse(request())) {
if (View::exists($entry->get('template'))) {
echo view($entry->get('template'), $entry);
} else if (View::exists(str($entry->structure()->handle())->singular()->toString())) {
echo view(str($entry->structure()->handle())->singular()->toString(), $entry);
}
}
$controller = new Rapidez\Statamic\Http\Controllers\StatamicRewriteController();
$controller(request());
22 changes: 22 additions & 0 deletions src/Http/Controllers/StatamicRewriteController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Rapidez\Statamic\Http\Controllers;

use Illuminate\Http\Request;
use Statamic\Facades\Entry;
use Illuminate\Support\Facades\View;

class StatamicRewriteController
{
public function __invoke(Request $request)
{
$entry = Entry::query()
->where('collection', 'pages')
->where('slug', $request->path() == '/' ? 'home' : $request->path())
->first();

$template = View::exists($entry->get('template')) ? $entry->get('template') : $entry->blueprint->handle();

echo view($template, ['entry' => $entry]);
}
}

0 comments on commit 69d2d1f

Please sign in to comment.