-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved readability of code and data collection that is returned (#6)
- Loading branch information
Showing
2 changed files
with
24 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
} |