crud user

pull/1/head
Aji Kamaludin 5 years ago
parent eda2e94a70
commit ab39741822
No known key found for this signature in database
GPG Key ID: 23E2BDC458317AF8

@ -65,6 +65,8 @@ class SiswaController extends Controller
if($request->is_yatim != null){
$siswa->is_yatim = 1;
}else{
$siswa->is_yatim = 0;
}
if($siswa->save()){

@ -83,17 +83,6 @@ class TagihanController extends Controller
}
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*

@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
class UserController extends Controller
{
@ -13,7 +14,7 @@ class UserController extends Controller
*/
public function index()
{
$users = App\User::orderBy('created_at','desc')->paginate(5);
$users = User::orderBy('created_at','desc')->paginate(5);
return view('users.index', ['users' => $users]);
}
@ -24,7 +25,7 @@ class UserController extends Controller
*/
public function create()
{
//
return view('users.form');
}
/**
@ -35,18 +36,24 @@ class UserController extends Controller
*/
public function store(Request $request)
{
//
}
$request->validate([
'name' => 'required|max:255',
'email' => 'required|email|unique:users',
'password' => 'required|confirmed|min:8',
'role' => 'required|in:SuperAdmin,Admin,Bendahara'
]);
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
if(User::create($request->input())){
return redirect()->route('user.index')->with([
'type' => 'success',
'msg' => 'Pengguna ditambahkan'
]);
}else{
return redirect()->route('user.index')->with([
'type' => 'danger',
'msg' => 'Err.., Terjadi Kesalahan'
]);
}
}
/**
@ -55,9 +62,9 @@ class UserController extends Controller
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
public function edit(User $user)
{
//
return view('users.form', ['user' => $user]);
}
/**
@ -67,9 +74,32 @@ class UserController extends Controller
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
public function update(Request $request, User $user)
{
//
$request->validate([
'name' => 'required|max:255',
'email' => 'required|email|unique:users,email,'.$user->id,
'password' => 'nullable|confirmed|min:8',
'role' => 'required|in:SuperAdmin,Admin,Bendahara'
]);
if($request->password != null){
$user->fill($request->input());
}else{
$user->fill($request->except('password'));
}
if($user->save()){
return redirect()->route('user.index')->with([
'type' => 'success',
'msg' => 'Pengguna diubah'
]);
}else{
return redirect()->route('user.index')->with([
'type' => 'danger',
'msg' => 'Err.., Terjadi Kesalahan'
]);
}
}
/**
@ -78,8 +108,18 @@ class UserController extends Controller
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
public function destroy(User $user)
{
//
if($user->delete()){
return redirect()->route('user.index')->with([
'type' => 'success',
'msg' => 'Pengguna dihapus'
]);
}else{
return redirect()->route('user.index')->with([
'type' => 'danger',
'msg' => 'Err.., Terjadi Kesalahan'
]);
}
}
}

@ -17,7 +17,7 @@
<a href="{{ route('kelas.create') }}" class="btn btn-outline-primary btn-sm ml-5">Tambah Kelas</a>
</div>
@if(session()->has('msg'))
<div class="alert alert-{{ session()->get('type') }}" id="message" style="border-radius: 0px !important">
<div class="card-alert alert alert-{{ session()->get('type') }}" id="message" style="border-radius: 0px !important">
@if(session()->get('type') == 'success')
<i class="fe fe-check mr-2" aria-hidden="true"></i>
@else

@ -17,7 +17,7 @@
<a href="{{ route('periode.create') }}" class="btn btn-outline-primary btn-sm ml-5">Tambah Periode</a>
</div>
@if(session()->has('msg'))
<div class="alert alert-{{ session()->get('type') }}" id="message" style="border-radius: 0px !important">
<div class="card-alert alert alert-{{ session()->get('type') }}" id="message" style="border-radius: 0px !important">
@if(session()->get('type') == 'success')
<i class="fe fe-check mr-2" aria-hidden="true"></i>
@else

@ -48,7 +48,7 @@
<i class="fe fe-folder"></i> Kuitansi
</a>
</li>
@if(Auth::user()->role == 'Admin')
@if(Auth::user()->role == 'Admin' || Auth::user()->role == 'SuperAdmin')
<li class="nav-item">
<a href="{{ route('user.index') }}" class="nav-link {{ set_active(['user.*'], 'active') }}">
<i class="fe fe-box"></i> Pengguna

@ -32,7 +32,7 @@
</div>
</div>
@if(session()->has('msg'))
<div class="alert alert-{{ session()->get('type') }}" id="message" style="border-radius: 0px !important">
<div class="card-alert alert alert-{{ session()->get('type') }}" id="message" style="border-radius: 0px !important">
@if(session()->get('type') == 'success')
<i class="fe fe-check mr-2" aria-hidden="true"></i>
@else

@ -17,7 +17,7 @@
<a href="{{ route('tagihan.create') }}" class="btn btn-outline-primary btn-sm ml-5">Tambah Tagihan</a>
</div>
@if(session()->has('msg'))
<div class="alert alert-{{ session()->get('type') }}" id="message" style="border-radius: 0px !important">
<div class="card-alert alert alert-{{ session()->get('type') }}" id="message" style="border-radius: 0px !important">
@if(session()->get('type') == 'success')
<i class="fe fe-check mr-2" aria-hidden="true"></i>
@else
@ -28,7 +28,7 @@
@endif
<div class="table-responsive">
<table class="table card-table table-hover table-vcenter text-nowrap">
<table class="table card-table table-hover table-vcenter text-wrap">
<thead>
<tr>
<th class="w-1">No.</th>
@ -48,14 +48,14 @@
<td>
{{ $item->jumlah_idr }}
</td>
<td>
<td style="max-width: 150px">
@if($item->wajib_semua != null)
<p>Wajib Semua</p>
@elseif($item->kelas_id != null)
<p>{{ $item->kelas->nama }} {{ isset($item->kelas->periode) ? ' - '.$item->kelas->periode->nama : '' }}</p>
@elseif($item->wajib_semua == null && $item->kelas_id == null)
@foreach ($item->role as $role)
{{ $role->siswa->nama }}{{ " (".$role->siswa->kelas->nama.")" }},
{{ $role->siswa->nama }}{{ " (".$role->siswa->kelas->nama.")" }},
@endforeach
@endif
</td>

@ -0,0 +1,69 @@
@extends('layouts.app')
@section('site-name','Sistem Informasi SPP')
@section('page-name', (isset($user) ? 'Ubah Pengguna' : 'Pengguna Baru'))
@section('content')
<div class="row">
<div class="col-8">
<form action="{{ (isset($user) ? route('user.update', $user->id) : route('user.create')) }}" method="post" class="card">
<div class="card-header">
<h3 class="card-title">@yield('page-name')</h3>
</div>
<div class="card-body">
@if($errors->any())
<div class="alert alert-danger">
@foreach($errors->all() as $error)
{{ $error }}<br>
@endforeach
</div>
@endif
<div class="row">
<div class="col-12">
@csrf
<div class="form-group">
<label class="form-label">Nama</label>
<input type="text" class="form-control" name="name" placeholder="Nama" value="{{ isset($user) ? $user->name : old('name') }}" required>
</div>
<div class="form-group">
<label class="form-label">EMail</label>
<input type="text" class="form-control" name="email" placeholder="Email" value="{{ isset($user) ? $user->email : old('email') }}" required>
</div>
<div class="form-group">
<label class="form-label">Password</label>
<input type="password" class="form-control" name="password" value="" {{ isset($user) ? '' : 'required' }}>
</div>
<div class="form-group">
<label class="form-label">Konfirmasi Password</label>
<input type="password" class="form-control" name="password_confirmation" value="" {{ isset($user) ? '' : 'required' }}>
</div>
<div class="form-group">
<label class="form-label">Status</label>
<select id="select-beast" class="form-control custom-select" name="role">
<option value="SuperAdmin" {{ isset($user) ? ($user->role == 'SuperAdmin' ? 'selected' : '') : '' }}>Super Admin</option>
<option value="Admin" {{ isset($user) ? ($user->role == 'Admin' ? 'selected' : '') : '' }}>Admin</option>
<option value="Bendahara" {{ isset($user) ? ($user->role == 'Bendahara' ? 'selected' : '') : '' }}>Bendahara</option>
</select>
</div>
</div>
</div>
</div>
<div class="card-footer text-right">
<div class="d-flex">
<a href="{{ url()->previous() }}" class="btn btn-link">Batal</a>
<button type="submit" class="btn btn-primary ml-auto">Simpan</button>
</div>
</div>
</form>
</div>
</div>
@endsection
@section('js')
<script>
require(['jquery', 'selectize'], function ($, selectize) {
$(document).ready(function () {
$('#select-beast').selectize({});
});
});
</script>
@endsection

@ -0,0 +1,110 @@
@extends('layouts.app')
@section('site-name','Sistem Informasi SPP')
@section('page-name','Pengguna')
@section('content')
<div class="page-header">
<h1 class="page-title">
@yield('page-name')
</h1>
</div>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h3 class="card-title">@yield('page-name')</h3>
<a href="{{ route('user.create') }}" class="btn btn-outline-primary btn-sm ml-5">Tambah Pengguna</a>
</div>
@if(session()->has('msg'))
<div class="card-alert alert alert-{{ session()->get('type') }}" id="message" style="border-radius: 0px !important">
@if(session()->get('type') == 'success')
<i class="fe fe-check mr-2" aria-hidden="true"></i>
@else
<i class="fe fe-alert-triangle mr-2" aria-hidden="true"></i>
@endif
{{ session()->get('msg') }}
</div>
@endif
<div class="table-responsive">
<table class="table card-table table-hover table-vcenter text-nowrap">
<thead>
<tr>
<th class="w-1">No.</th>
<th>Nama</th>
<th>Email</th>
<th>Tanggal</th>
<th>Status</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach ($users as $index => $item)
<tr>
<td><span class="text-muted">{{ $index+1 }}</span></td>
<td>
@if(Auth::user()->id == $item->id)
<span class="tag tag-teal">{{ $item->name }}</span>
@else
{{ $item->name }}
@endif
</td>
<td>{{ $item->email }}</td>
<td>{{ $item->created_at->format('d-m-Y') }}</td>
<td>{{ $item->role }}</td>
<td class="text-center">
<a class="icon" href="{{ route('user.edit', $item->id) }}" title="edit item">
<i class="fe fe-edit"></i>
</a>
@if(Auth::user()->id != $item->id)
<a class="icon btn-delete" href="#!" data-id="{{ $item->id }}" title="delete item">
<i class="fe fe-trash"></i>
</a>
@endif
<form action="{{ route('user.destroy', $item->id) }}" method="POST" id="form-{{ $item->id }}">
@csrf
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="card-footer">
<div class="d-flex">
<div class="ml-auto mb-0">
{{ $users->links() }}
</div>
</div>
</div>
</div>
</div>
</div>
@endsection
@section('js')
<script>
require(['jquery', 'sweetalert'], function ($, sweetalert) {
$(document).ready(function () {
$(document).on('click','.btn-delete', function(){
formid = $(this).attr('data-id');
swal({
title: 'Anda yakin ingin menghapus?',
text: 'user yang dihapus tidak dapat dikembalikan',
dangerMode: true,
buttons: {
cancel: true,
confirm: true,
},
}).then((result) => {
if (result) {
$('#form-' + formid).submit();
}
})
})
});
});
</script>
@endsection
Loading…
Cancel
Save