2019-02-11 23:25:46 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
2019-03-14 00:05:11 +09:00
|
|
|
use App\Http\Controllers\Controller;
|
2019-03-16 12:22:07 +09:00
|
|
|
use App\Http\Requests\AdminInfoStoreRequest;
|
2019-02-11 23:25:46 +09:00
|
|
|
use App\Information;
|
|
|
|
use Illuminate\Http\Request;
|
2019-03-14 00:04:53 +09:00
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
use Illuminate\Validation\Rule;
|
2019-02-11 23:25:46 +09:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2019-03-14 00:04:53 +09:00
|
|
|
return view('admin.info.create')->with([
|
|
|
|
'categories' => Information::CATEGORIES
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-03-16 12:22:07 +09:00
|
|
|
public function store(AdminInfoStoreRequest $request)
|
2019-03-14 00:04:53 +09:00
|
|
|
{
|
|
|
|
$inputs = $request->all();
|
|
|
|
if (!$request->has('pinned')) {
|
|
|
|
$inputs['pinned'] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$info = Information::create($inputs);
|
|
|
|
|
|
|
|
return redirect()->route('admin.info.edit', ['info' => $info])->with('status', 'お知らせを更新しました。');
|
2019-02-11 23:25:46 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public function edit($id)
|
|
|
|
{
|
|
|
|
$information = Information::findOrFail($id);
|
|
|
|
|
|
|
|
return view('admin.info.edit')->with([
|
|
|
|
'info' => $information,
|
|
|
|
'categories' => Information::CATEGORIES
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-03-16 12:22:07 +09:00
|
|
|
public function update(AdminInfoStoreRequest $request, Information $info)
|
2019-02-11 23:25:46 +09:00
|
|
|
{
|
2019-03-14 00:04:53 +09:00
|
|
|
$inputs = $request->all();
|
|
|
|
if (!$request->has('pinned')) {
|
|
|
|
$inputs['pinned'] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$info->fill($inputs)->save();
|
|
|
|
|
|
|
|
return redirect()->route('admin.info.edit', ['info' => $info])->with('status', 'お知らせを更新しました。');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy(Information $info)
|
|
|
|
{
|
|
|
|
$info->delete();
|
|
|
|
|
|
|
|
return redirect()->route('admin.info')->with('status', 'お知らせを削除しました。');
|
2019-02-11 23:25:46 +09:00
|
|
|
}
|
|
|
|
}
|