日付の表示変換は、controllerではなく、viewに変数を渡して、view側で表示を変える。
## 前準備
admin用のテンプレートをlayoutsフォルダ配下に格納する
./resources/view/layouts/admin.blade.php
{{asset()}}はpublicディレクトリにリンクする
<link href="{{asset('css/app.css')}}" rel="stylesheet">
<link href="{{asset('css/libs.css')}}" rel="stylesheet">
./resources/view/admin/index.blade.php
@extends('layouts.admin')
route
Route::get('/admin', function(){
return view('admin.index');
});
./resources/view/asset/sass/app.scss
#admin-page {
padding-top: 0px;
}
$ gulp
## データ取り込み
Controller: AdminUserController.php
public function index()
{
//
$users = User::all();
return view('admin.users.index', compact('users'));
}
## View
view: index.blade.php
<table class="table table-striped">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Created</th>
<th>Updated</th>
</tr>
</thead>
<tbody>
@if($users)
@foreach($users as $user)
<tr>
<td>{{$user->id}}</td>
<td>{{$user->name}}</td>
<td>{{$user->email}}</td>
<td>{{$user->created_at->diffForHumans()}}</td>
<td>{{$user->updated_at->diffForHumans()}}</td>
</tr>
@endforeach
@endif
</tbody>
</table>
日付で表示を変えるのはわかったが、カラム同士の値の引き算で時間を計算する際も、view側で書くのだろか?要検討。