未ログイントップにお知らせを置いてみた

This commit is contained in:
shibafu 2018-01-05 22:27:16 +09:00
parent 3ea9476aa8
commit 69f619e2af
2 changed files with 17 additions and 8 deletions

View File

@ -27,7 +27,6 @@ class HomeController extends Controller
*/
public function index()
{
if (Auth::check()) {
$informations = Information::query()
->select('id', 'category', 'pinned', 'title', 'created_at')
->orderByDesc('pinned')
@ -35,9 +34,10 @@ class HomeController extends Controller
->paginate(3);
$categories = Information::CATEGORIES;
if (Auth::check()) {
return view('home')->with(compact('informations', 'categories'));
} else {
return view('guest');
return view('guest')->with(compact('informations', 'categories'));
}
}
}

View File

@ -27,5 +27,14 @@
<p>ティッシュが蒸発するような人気のオカズや、底なしの体力を競い合うランキングなど、Webならではのサービスも用意<s class="grey-text">しています</s>したいですね。</p>
</div>
</div>
<h4 class="mt-5 mb-4">お知らせ</h4>
<div class="list-group list-group-flush">
@foreach($informations as $info)
<a class="list-group-item" href="{{ route('info.show', ['id' => $info->id]) }}">
<span class="badge {{ $categories[$info->category]['class'] }}">{{ $categories[$info->category]['label'] }}</span> {{ $info->title }} <small class="text-secondary">- {{ $info->created_at->format('n月j日') }}</small>
</a>
@endforeach
<a href="{{ route('info') }}" class="list-group-item text-right">お知らせ一覧 &raquo;</a>
</div>
</div>
@endsection