お知らせ編集画面の表示のみ実装
This commit is contained in:
parent
e69adbfbc3
commit
53ac4c9b8f
44
app/Http/Controllers/Admin/InfoController.php
Normal file
44
app/Http/Controllers/Admin/InfoController.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Information;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
|
||||||
|
class InfoController extends Controller
|
||||||
|
{
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$informations = Information::query()
|
||||||
|
->select('id', 'category', 'pinned', 'title', 'created_at')
|
||||||
|
->orderByDesc('pinned')
|
||||||
|
->orderByDesc('created_at')
|
||||||
|
->paginate(20);
|
||||||
|
|
||||||
|
return view('admin.info.index')->with([
|
||||||
|
'informations' => $informations,
|
||||||
|
'categories' => Information::CATEGORIES
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit($id)
|
||||||
|
{
|
||||||
|
$information = Information::findOrFail($id);
|
||||||
|
|
||||||
|
return view('admin.info.edit')->with([
|
||||||
|
'info' => $information,
|
||||||
|
'categories' => Information::CATEGORIES
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(Request $request)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
}
|
48
resources/views/admin/info/edit.blade.php
Normal file
48
resources/views/admin/info/edit.blade.php
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
@extends('layouts.admin')
|
||||||
|
|
||||||
|
@section('title', 'お知らせ')
|
||||||
|
|
||||||
|
@section('tab-content')
|
||||||
|
<div class="container">
|
||||||
|
<h2>お知らせの編集</h2>
|
||||||
|
<hr>
|
||||||
|
<form action="{{ route('admin.info.update', ['id' => $info->id]) }}" method="post">
|
||||||
|
{{ method_field('PUT') }}
|
||||||
|
{{ csrf_field() }}
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="form-group col-12 col-lg-6">
|
||||||
|
<label for="category">カテゴリ</label>
|
||||||
|
<select id="category" name="category" class="form-control">
|
||||||
|
@foreach($categories as $id => $category)
|
||||||
|
<option value="{{ $id }}" {{ (old('category') ?? $info->category) == $id ? 'checked' : '' }}>{{ $category['label'] }}</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-12 col-lg-6 d-flex flex-column justify-content-center">
|
||||||
|
<div class="custom-control custom-checkbox">
|
||||||
|
<input id="pinned" type="checkbox" class="custom-control-input"
|
||||||
|
{{ (is_bool(old('pinned')) ? old('pinned') : $info->pinned) ? 'checked' : ''}}>
|
||||||
|
<label for="pinned" class="custom-control-label">ピン留め (常に優先表示) する</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="title">タイトル</label>
|
||||||
|
<input id="title" name="title" type="text" class="form-control" value="{{ old('title') ?? $info->title }}">
|
||||||
|
</div>
|
||||||
|
<div class="form-group mt-3">
|
||||||
|
<label for="content">本文</label>
|
||||||
|
<textarea id="content" name="content" rows="15" class="form-control" maxlength="10000">{{ old('content') ?? $info->content }}</textarea>
|
||||||
|
<small class="form-text text-muted">
|
||||||
|
最大 10000 文字、Markdown 形式
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-between">
|
||||||
|
<button type="submit" class="btn btn-primary">更新</button>
|
||||||
|
<button type="button" class="btn btn-danger">削除</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
@endsection
|
57
resources/views/admin/info/index.blade.php
Normal file
57
resources/views/admin/info/index.blade.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
@extends('layouts.admin')
|
||||||
|
|
||||||
|
@section('title', 'お知らせ')
|
||||||
|
|
||||||
|
@section('tab-content')
|
||||||
|
<div class="container">
|
||||||
|
<h2>お知らせ</h2>
|
||||||
|
<hr>
|
||||||
|
<div class="d-flex mb-3">
|
||||||
|
<a href="{{ route('admin.info.create') }}" class="btn btn-primary">新規作成</a>
|
||||||
|
</div>
|
||||||
|
<table class="table table-sm">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>カテゴリ</th>
|
||||||
|
<th>タイトル</th>
|
||||||
|
<th>作成日</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach($informations as $info)
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@if ($info->pinned)
|
||||||
|
<span class="badge badge-secondary"><span class="oi oi-pin"></span>ピン留め</span>
|
||||||
|
@endif
|
||||||
|
<span class="badge {{ $categories[$info->category]['class'] }}">{{ $categories[$info->category]['label'] }}</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="{{ route('admin.info.edit', ['id' => $info->id]) }}">{{ $info->title }}</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ $info->created_at->format('Y年n月j日') }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<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">«</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">»</span>
|
||||||
|
<span class="sr-only">Next</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
@endsection
|
@ -4,12 +4,12 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-3">
|
<div class="col-lg-3">
|
||||||
<div class="list-group">
|
<div class="list-group mb-4">
|
||||||
<div class="list-group-item disabled font-weight-bold">管理</div>
|
<div class="list-group-item disabled font-weight-bold">管理</div>
|
||||||
<a class="list-group-item list-group-item-action {{ Route::currentRouteName() === 'admin.dashboard' ? 'active' : '' }}"
|
<a class="list-group-item list-group-item-action {{ Route::is('admin.dashboard') ? 'active' : '' }}"
|
||||||
href="{{ route('admin.dashboard') }}"><span class="oi oi-dashboard mr-1"></span> ダッシュボード</a>
|
href="{{ route('admin.dashboard') }}"><span class="oi oi-dashboard mr-1"></span> ダッシュボード</a>
|
||||||
<a class="list-group-item list-group-item-action"
|
<a class="list-group-item list-group-item-action {{ Route::is('admin.info*') ? 'active' : '' }}"
|
||||||
href=""><span class="oi oi-bullhorn mr-1"></span> お知らせ</a>
|
href="{{ route('admin.info') }}"><span class="oi oi-bullhorn mr-1"></span> お知らせ</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-content col-lg-9">
|
<div class="tab-content col-lg-9">
|
||||||
|
@ -51,4 +51,8 @@ Route::middleware('can:admin')
|
|||||||
->name('admin.')
|
->name('admin.')
|
||||||
->group(function () {
|
->group(function () {
|
||||||
Route::get('/', 'DashboardController@index')->name('dashboard');
|
Route::get('/', 'DashboardController@index')->name('dashboard');
|
||||||
|
Route::get('/info', 'InfoController@index')->name('info');
|
||||||
|
Route::get('/info/create', 'InfoController@create')->name('info.create');
|
||||||
|
Route::get('/info/{id}', 'InfoController@edit')->name('info.edit');
|
||||||
|
Route::put('/info/{id}', 'InfoController@update')->name('info.update');
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user