Commit 2a0e1c32 authored by m-wynn's avatar m-wynn

ユーザ画面作成

php artisan infyom:scaffold Questionnaireの結果
parent 51b3233e
<?php
namespace App\Http\Controllers;
use App\Http\Requests\CreateUserRequest;
use App\Http\Requests\UpdateUserRequest;
use App\Http\Controllers\AppBaseController;
use App\Repositories\UserRepository;
use Illuminate\Http\Request;
use Flash;
class UserController extends AppBaseController
{
/** @var UserRepository $userRepository*/
private $userRepository;
public function __construct(UserRepository $userRepo)
{
$this->userRepository = $userRepo;
}
/**
* Display a listing of the User.
*/
public function index(Request $request)
{
$users = $this->userRepository->paginate(10);
return view('users.index')
->with('users', $users);
}
/**
* Show the form for creating a new User.
*/
public function create()
{
return view('users.create');
}
/**
* Store a newly created User in storage.
*/
public function store(CreateUserRequest $request)
{
$input = $request->all();
$user = $this->userRepository->create($input);
Flash::success('User saved successfully.');
return redirect(route('users.index'));
}
/**
* Display the specified User.
*/
public function show($id)
{
$user = $this->userRepository->find($id);
if (empty($user)) {
Flash::error('User not found');
return redirect(route('users.index'));
}
return view('users.show')->with('user', $user);
}
/**
* Show the form for editing the specified User.
*/
public function edit($id)
{
$user = $this->userRepository->find($id);
if (empty($user)) {
Flash::error('User not found');
return redirect(route('users.index'));
}
return view('users.edit')->with('user', $user);
}
/**
* Update the specified User in storage.
*/
public function update($id, UpdateUserRequest $request)
{
$user = $this->userRepository->find($id);
if (empty($user)) {
Flash::error('User not found');
return redirect(route('users.index'));
}
$user = $this->userRepository->update($request->all(), $id);
Flash::success('User updated successfully.');
return redirect(route('users.index'));
}
/**
* Remove the specified User from storage.
*
* @throws \Exception
*/
public function destroy($id)
{
$user = $this->userRepository->find($id);
if (empty($user)) {
Flash::error('User not found');
return redirect(route('users.index'));
}
$this->userRepository->delete($id);
Flash::success('User deleted successfully.');
return redirect(route('users.index'));
}
}
<?php
namespace App\Http\Requests;
use App\Models\User;
use Illuminate\Foundation\Http\FormRequest;
class CreateUserRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return User::$rules;
}
}
<?php
namespace App\Http\Requests;
use App\Models\User;
use Illuminate\Foundation\Http\FormRequest;
class UpdateUserRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$rules = User::$rules;
return $rules;
}
}
......@@ -42,4 +42,14 @@ class User extends Authenticatable
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
/**
* Validation
*
*/
public static array $rules = [
'name' => 'required',
'email' => 'required',
'password' => 'required'
];
}
<?php
namespace App\Repositories;
use App\Models\User;
use App\Repositories\BaseRepository;
class UserRepository extends BaseRepository
{
protected $fieldSearchable = [
'name',
'email',
'password'
];
public function getFieldsSearchable(): array
{
return $this->fieldSearchable;
}
public function model(): string
{
return User::class;
}
}
[
{
"name": "id",
"dbType": "id",
"htmlType": "",
"validations": "",
"searchable": false,
"fillable": false,
"primary": true,
"inForm": false,
"inIndex": false,
"inView": false
},
{
"name": "name",
"dbType": "string",
"htmlType": "text",
"validations": "required",
"searchable": true,
"fillable": true,
"primary": false,
"inForm": true,
"inIndex": true,
"inView": true
},
{
"name": "email",
"dbType": "string",
"htmlType": "email",
"validations": "required",
"searchable": true,
"fillable": true,
"primary": false,
"inForm": true,
"inIndex": true,
"inView": true
},
{
"name": "password",
"dbType": "string",
"htmlType": "password",
"validations": "required",
"searchable": true,
"fillable": true,
"primary": false,
"inForm": true,
"inIndex": true,
"inView": true
},
{
"name": "created_at",
"dbType": "timestamp",
"htmlType": "",
"validations": "",
"searchable": false,
"fillable": false,
"primary": false,
"inForm": false,
"inIndex": false,
"inView": true
},
{
"name": "updated_at",
"dbType": "timestamp",
"htmlType": "",
"validations": "",
"searchable": false,
"fillable": false,
"primary": false,
"inForm": false,
"inIndex": false,
"inView": true
}
]
\ No newline at end of file
......@@ -12,3 +12,10 @@
<p>Questionnaires</p>
</a>
</li>
<li class="nav-item">
<a href="{{ route('users.index') }}" class="nav-link {{ Request::is('users*') ? 'active' : '' }}">
<i class="nav-icon fas fa-home"></i>
<p>Users</p>
</a>
</li>
@extends('layouts.app')
@section('content')
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-12">
<h1>
Create Users
</h1>
</div>
</div>
</div>
</section>
<div class="content px-3">
@include('adminlte-templates::common.errors')
<div class="card">
{!! Form::open(['route' => 'users.store']) !!}
<div class="card-body">
<div class="row">
@include('users.fields')
</div>
</div>
<div class="card-footer">
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
<a href="{{ route('users.index') }}" class="btn btn-default"> Cancel </a>
</div>
{!! Form::close() !!}
</div>
</div>
@endsection
@extends('layouts.app')
@section('content')
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-12">
<h1>
Edit User
</h1>
</div>
</div>
</div>
</section>
<div class="content px-3">
@include('adminlte-templates::common.errors')
<div class="card">
{!! Form::model($user, ['route' => ['users.update', $user->id], 'method' => 'patch']) !!}
<div class="card-body">
<div class="row">
@include('users.fields')
</div>
</div>
<div class="card-footer">
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
<a href="{{ route('users.index') }}" class="btn btn-default"> Cancel </a>
</div>
{!! Form::close() !!}
</div>
</div>
@endsection
<!-- Name Field -->
<div class="form-group col-sm-6">
{!! Form::label('name', 'Name:') !!}
{!! Form::text('name', null, ['class' => 'form-control', 'required']) !!}
</div>
<!-- Email Field -->
<div class="form-group col-sm-6">
{!! Form::label('email', 'Email:') !!}
{!! Form::email('email', null, ['class' => 'form-control', 'required']) !!}
</div>
<!-- password Field -->
<div class="form-group col-sm-6">
{!! Form::label('password', 'Password:') !!}
{!! Form::password('password', ['class' => 'form-control', 'required']) !!}
</div>
\ No newline at end of file
@extends('layouts.app')
@section('content')
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1>Users</h1>
</div>
<div class="col-sm-6">
<a class="btn btn-primary float-right"
href="{{ route('users.create') }}">
Add New
</a>
</div>
</div>
</div>
</section>
<div class="content px-3">
@include('flash::message')
<div class="clearfix"></div>
<div class="card">
@include('users.table')
</div>
</div>
@endsection
@extends('layouts.app')
@section('content')
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1>
User Details
</h1>
</div>
<div class="col-sm-6">
<a class="btn btn-default float-right"
href="{{ route('users.index') }}">
Back
</a>
</div>
</div>
</div>
</section>
<div class="content px-3">
<div class="card">
<div class="card-body">
<div class="row">
@include('users.show_fields')
</div>
</div>
</div>
</div>
@endsection
<!-- Name Field -->
<div class="col-sm-12">
{!! Form::label('name', 'Name:') !!}
<p>{{ $user->name }}</p>
</div>
<!-- Email Field -->
<div class="col-sm-12">
{!! Form::label('email', 'Email:') !!}
<p>{{ $user->email }}</p>
</div>
<!-- Password Field -->
<div class="col-sm-12">
{!! Form::label('password', 'Password:') !!}
<p>{{ $user->password }}</p>
</div>
<!-- Created At Field -->
<div class="col-sm-12">
{!! Form::label('created_at', 'Created At:') !!}
<p>{{ $user->created_at }}</p>
</div>
<!-- Updated At Field -->
<div class="col-sm-12">
{!! Form::label('updated_at', 'Updated At:') !!}
<p>{{ $user->updated_at }}</p>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table" id="users-table">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Password</th>
<th colspan="3">Action</th>
</tr>
</thead>
<tbody>
@foreach($users as $user)
<tr>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td>{{ $user->password }}</td>
<td style="width: 120px">
{!! Form::open(['route' => ['users.destroy', $user->id], 'method' => 'delete']) !!}
<div class='btn-group'>
<a href="{{ route('users.show', [$user->id]) }}"
class='btn btn-default btn-xs'>
<i class="far fa-eye"></i>
</a>
<a href="{{ route('users.edit', [$user->id]) }}"
class='btn btn-default btn-xs'>
<i class="far fa-edit"></i>
</a>
{!! Form::button('<i class="far fa-trash-alt"></i>', ['type' => 'submit', 'class' => 'btn btn-danger btn-xs', 'onclick' => "return confirm('Are you sure?')"]) !!}
</div>
{!! Form::close() !!}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="card-footer clearfix">
<div class="float-right">
@include('adminlte-templates::common.paginate', ['records' => $users])
</div>
</div>
</div>
......@@ -22,3 +22,4 @@ Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name
Auth::routes();
Route::resource('questionnaires', App\Http\Controllers\QuestionnaireController::class);
Route::resource('users', App\Http\Controllers\UserController::class);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment