Skip to content
Permalink
Browse files

ユーザ一覧実装

  • Loading branch information
terumichi1209 committed Jun 28, 2019
1 parent 081a34a commit 21db8cd33c200af995149ad6cd9ecf851f6b5013
@@ -2,7 +2,7 @@
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Services\UserService;
use Illuminate\View\View;
class UserController extends Controller
@@ -12,6 +12,7 @@ class UserController extends Controller
*/
public function index(): View
{
return view('user.list');
$users = (new UserService())->list();
return view('user.list', ['users' => $users]);
}
}
@@ -0,0 +1,17 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
}
@@ -0,0 +1,17 @@
<?php
namespace App\Repositories;
use App\Models\User;
use \Illuminate\Database\Eloquent\Collection;
class UserRepository
{
/**
* @return Collection
*/
public function list(): Collection
{
return User::all();
}
}
@@ -0,0 +1,25 @@
<?php
namespace App\Services;
use App\Repositories\UserRepository;
use Illuminate\Database\Eloquent\Collection;
class UserService
{
/** UserRepository */
private $user_repos;
public function __construct()
{
$this->user_repos = new UserRepository;
}
/**
* @return Collection
*/
public function list(): Collection
{
return $this->user_repos->list();
}
}
@@ -4,6 +4,24 @@
<title>Laravel Test</title>
</head>
<body>
Hello World!
@if (session('success_message'))
<div>{{ session('success_message') }}</div>
@elseif (session('error_message'))
<div>{{ session('error_message') }}</div>
@endif
<h1>ユーザ一覧</h1>
<a href="/user/create">ユーザ作成</a>
<table>
<tr>
<th>ユーザ名</th>
<th>メールアドレス</th>
</tr>
@foreach ($users as $user)
<tr>
<td>{{$user->name}}</td>
<td>{{$user->email}}</td>
</tr>
@endforeach
</table>
</body>
</html>

0 comments on commit 21db8cd

Please sign in to comment.
You can’t perform that action at this time.