お知らせ画面の追加

This commit is contained in:
shibafu 2017-11-03 20:38:09 +09:00
parent edcc2bceaf
commit d94c444b55
10 changed files with 158 additions and 7 deletions

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Ejaculation;
use App\Information;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
@ -71,7 +72,14 @@ FROM
SQL
, ['user_id' => Auth::id()]);
return view('home')->with(compact('ejaculations', 'currentSession', 'summary'));
$informations = Information::query()
->select('id', 'category', 'pinned', 'title', 'created_at')
->orderBy('pinned')
->orderByDesc('created_at')
->paginate(3);
$categories = Information::CATEGORIES;
return view('home')->with(compact('ejaculations', 'currentSession', 'summary', 'informations', 'categories'));
} else {
return view('guest');
}

View File

@ -0,0 +1,34 @@
<?php
namespace App\Http\Controllers;
use App\Information;
use Illuminate\Http\Request;
class InfoController extends Controller
{
public function index()
{
$informations = Information::query()
->select('id', 'category', 'pinned', 'title', 'created_at')
->orderBy('pinned')
->orderByDesc('created_at')
->paginate(20);
return view('info.index')->with([
'informations' => $informations,
'categories' => Information::CATEGORIES
]);
}
public function show($id)
{
$information = Information::findOrFail($id);
$parser = new \Parsedown();
$compiledContent = $parser->text($information->content);
return view('info.show')->with([
'info' => $information,
'category' => Information::CATEGORIES[$information->category],
'compiledContent' => $compiledContent
]);
}
}

20
app/Information.php Normal file
View File

@ -0,0 +1,20 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Information extends Model
{
use SoftDeletes;
const CATEGORIES = [
0 => ['label' => 'お知らせ', 'class' => 'badge-info'],
1 => ['label' => 'アップデート', 'class' => 'badge-success'],
2 => ['label' => '不具合情報', 'class' => 'badge-danger'],
3 => ['label' => 'メンテナンス', 'class' => 'badge-warning']
];
protected $dates = ['deleted_at'];
}

View File

@ -6,6 +6,7 @@
"type": "project",
"require": {
"php": ">=7.0.0",
"erusev/parsedown": "^1.6",
"laravel/framework": "5.5.*",
"laravel/tinker": "~1.0"
},

2
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "eed5a1a98b90f1543f877bbea7faf5ed",
"content-hash": "d5db680b40d4d68ebfb31b031548657a",
"packages": [
{
"name": "dnoegel/php-xdg-base-dir",

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateInformationTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('information', function (Blueprint $table) {
$table->increments('id');
$table->integer('category');
$table->boolean('pinned')->default(false);
$table->text('title');
$table->text('content');
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('information');
}
}

View File

@ -35,10 +35,12 @@
<div class="card mb-4">
<div class="card-header">サイトからのお知らせ</div>
<div class="list-group list-group-flush">
<a href="#" class="list-group-item"><span class="badge badge-danger">重要</span> オープンβテスト 第2シーズンとしてサービス中</a>
<a href="#" class="list-group-item"><span class="badge badge-info">アップデート</span> ver.2017-[season] アップデートのお知らせ</a>
<a href="#" class="list-group-item"><span class="badge badge-danger">不具合情報</span> 存在が不具合であることについて</a>
<a href="#" class="list-group-item text-right">お知らせ一覧 &raquo;</a>
@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>
<div class="card mb-4">

View File

@ -0,0 +1,32 @@
@extends('layouts.base')
@section('content')
<div class="container">
<h2>サイトからのお知らせ</h2>
<hr>
<div class="list-group">
@foreach($informations as $info)
<a class="list-group-item border-bottom-only pt-3 pb-3" 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
</div>
<ul class="pagination mt-4 justify-content-center">
<li class="page-item {{ $informations->currentPage() === 1 ? 'disabled' : '' }}">
<a class="page-link" href="{{ $informations->previousPageUrl() }}" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
<span class="sr-only">Previous</span>
</a>
</li>
@for ($i = 1; $i <= $informations->lastPage(); $i++)
<li class="page-item {{ $i === $informations->currentPage() ? 'active' : '' }}"><a href="{{ $informations->url($i) }}" class="page-link">{{ $i }}</a></li>
@endfor
<li class="page-item {{ $informations->currentPage() === $informations->lastPage() ? 'disabled' : '' }}">
<a class="page-link" href="{{ $informations->nextPageUrl() }}" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
<span class="sr-only">Next</span>
</a>
</li>
</ul>
</div>
@endsection

View File

@ -0,0 +1,15 @@
@extends('layouts.base')
@section('content')
<div class="container">
<nav aria-label="breadcrumb" role="navigation">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ route('info') }}">サイトからのお知らせ</a></li>
<li class="breadcrumb-item active" aria-current="page">{{ $info->created_at->format('Y年n月j日') }}</li>
</ol>
</nav>
<h2><span class="badge {{ $category['class'] }}">{{ $category['label'] }}</span> {{ $info->title }}</h2>
<p class="text-secondary"><span class="oi oi-calendar"></span> {{ $info->created_at->format('Y年n月j日') }}</p>
{!! $compiledContent !!}
</div>
@endsection

View File

@ -26,4 +26,7 @@ Route::middleware('auth')->group(function () {
Route::get('/checkin', 'EjaculationController@create')->name('checkin');
Route::post('/checkin', 'EjaculationController@store')->name('checkin');
Route::delete('/checkin/{id}', 'EjaculationController@destroy')->name('checkin.destroy');
});
});
Route::get('/info', 'InfoController@index')->name('info');
Route::get('/info/{id}', 'InfoController@show')->where('id', '[0-9]+')->name('info.show');