public static function getPage($key) { $key = trim($key); $key = preg_replace('/\\s+/', ' ', $key); $page = Page::where('slug', self::slug($key))->first(); if (!$page) { $page = Page::where('title', $key)->first(); if (!$page) { $page = new Page(); $page->rev = 0; $page->title = $key; $page->slug = null; // view 에서 slug가 없으면 title을 사용하므로 null 처리 $page->content = ''; } } return $page; }
<?php use NineCells\Pages\Models\Page; $pages = Page::orderBy('id', 'desc')->paginate(10); ?> <table class="table table-bordered"> <thead> <tr> <th>제목</th> <th>최근변경</th> <th>변경한 사람</th> </tr> </thead> <tbody> @foreach ( $pages as $page ) <tr> <td><a href="/pages/{{ $page->slug }}">{{ $page->title }}</a></td> <td>{{ $page->updated_at->diffForHumans() }}</td> <td><a href="/members/{{ $page->writer_id }}">{{ $page->writer->name }}</a></td> </tr> @endforeach </tbody> </table> {!! $pages->links() !!}