From d94c444b558330cd6fce51940f30d5e8a530d1ae Mon Sep 17 00:00:00 2001 From: shibafu Date: Fri, 3 Nov 2017 20:38:09 +0900 Subject: [PATCH] =?UTF-8?q?=E3=81=8A=E7=9F=A5=E3=82=89=E3=81=9B=E7=94=BB?= =?UTF-8?q?=E9=9D=A2=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/HomeController.php | 10 +++++- app/Http/Controllers/InfoController.php | 34 ++++++++++++++++++ app/Information.php | 20 +++++++++++ composer.json | 1 + composer.lock | 2 +- ..._11_03_182707_create_information_table.php | 36 +++++++++++++++++++ resources/views/home.blade.php | 10 +++--- resources/views/info/index.blade.php | 32 +++++++++++++++++ resources/views/info/show.blade.php | 15 ++++++++ routes/web.php | 5 ++- 10 files changed, 158 insertions(+), 7 deletions(-) create mode 100644 app/Http/Controllers/InfoController.php create mode 100644 app/Information.php create mode 100644 database/migrations/2017_11_03_182707_create_information_table.php create mode 100644 resources/views/info/index.blade.php create mode 100644 resources/views/info/show.blade.php diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index a3b447d..9659481 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -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'); } diff --git a/app/Http/Controllers/InfoController.php b/app/Http/Controllers/InfoController.php new file mode 100644 index 0000000..423eeba --- /dev/null +++ b/app/Http/Controllers/InfoController.php @@ -0,0 +1,34 @@ +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 + ]); + } +} diff --git a/app/Information.php b/app/Information.php new file mode 100644 index 0000000..e0ae6ed --- /dev/null +++ b/app/Information.php @@ -0,0 +1,20 @@ + ['label' => 'お知らせ', 'class' => 'badge-info'], + 1 => ['label' => 'アップデート', 'class' => 'badge-success'], + 2 => ['label' => '不具合情報', 'class' => 'badge-danger'], + 3 => ['label' => 'メンテナンス', 'class' => 'badge-warning'] + ]; + + protected $dates = ['deleted_at']; +} diff --git a/composer.json b/composer.json index 9a7f989..026373f 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,7 @@ "type": "project", "require": { "php": ">=7.0.0", + "erusev/parsedown": "^1.6", "laravel/framework": "5.5.*", "laravel/tinker": "~1.0" }, diff --git a/composer.lock b/composer.lock index da09051..2dd5121 100644 --- a/composer.lock +++ b/composer.lock @@ -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", diff --git a/database/migrations/2017_11_03_182707_create_information_table.php b/database/migrations/2017_11_03_182707_create_information_table.php new file mode 100644 index 0000000..8df1493 --- /dev/null +++ b/database/migrations/2017_11_03_182707_create_information_table.php @@ -0,0 +1,36 @@ +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'); + } +} diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index f163762..d3ad6e6 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -35,10 +35,12 @@
サイトからのお知らせ
diff --git a/resources/views/info/index.blade.php b/resources/views/info/index.blade.php new file mode 100644 index 0000000..fac5aa9 --- /dev/null +++ b/resources/views/info/index.blade.php @@ -0,0 +1,32 @@ +@extends('layouts.base') + +@section('content') +
+

サイトからのお知らせ

+
+ + +
+@endsection \ No newline at end of file diff --git a/resources/views/info/show.blade.php b/resources/views/info/show.blade.php new file mode 100644 index 0000000..47505f0 --- /dev/null +++ b/resources/views/info/show.blade.php @@ -0,0 +1,15 @@ +@extends('layouts.base') + +@section('content') +
+ +

{{ $category['label'] }} {{ $info->title }}

+

{{ $info->created_at->format('Y年n月j日') }}

+ {!! $compiledContent !!} +
+@endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 17879c1..704bc30 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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'); -}); \ No newline at end of file +}); + +Route::get('/info', 'InfoController@index')->name('info'); +Route::get('/info/{id}', 'InfoController@show')->where('id', '[0-9]+')->name('info.show'); \ No newline at end of file