From ab39741822724e2aa8fe23828bb3208e22542244 Mon Sep 17 00:00:00 2001 From: Aji Kamaludin Date: Wed, 5 Jun 2019 21:14:37 +0700 Subject: [PATCH] crud user --- app/Http/Controllers/SiswaController.php | 2 + app/Http/Controllers/TagihanController.php | 11 --- app/Http/Controllers/UserController.php | 78 +++++++++++---- resources/views/kelas/index.blade.php | 2 +- resources/views/periode/index.blade.php | 2 +- resources/views/shared/navbar.blade.php | 2 +- resources/views/siswa/index.blade.php | 2 +- resources/views/tagihan/index.blade.php | 8 +- resources/views/users/form.blade.php | 69 +++++++++++++ resources/views/users/index.blade.php | 110 +++++++++++++++++++++ 10 files changed, 248 insertions(+), 38 deletions(-) diff --git a/app/Http/Controllers/SiswaController.php b/app/Http/Controllers/SiswaController.php index c3d9d90..80df48f 100644 --- a/app/Http/Controllers/SiswaController.php +++ b/app/Http/Controllers/SiswaController.php @@ -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()){ diff --git a/app/Http/Controllers/TagihanController.php b/app/Http/Controllers/TagihanController.php index 398f543..7f8b244 100644 --- a/app/Http/Controllers/TagihanController.php +++ b/app/Http/Controllers/TagihanController.php @@ -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. * diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 0e98e80..0755c08 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -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' + ]); + } } } diff --git a/resources/views/kelas/index.blade.php b/resources/views/kelas/index.blade.php index 2455488..508ea55 100644 --- a/resources/views/kelas/index.blade.php +++ b/resources/views/kelas/index.blade.php @@ -17,7 +17,7 @@ Tambah Kelas @if(session()->has('msg')) -
+
@if(session()->get('type') == 'success') @else diff --git a/resources/views/periode/index.blade.php b/resources/views/periode/index.blade.php index 097ed53..2be7a1a 100644 --- a/resources/views/periode/index.blade.php +++ b/resources/views/periode/index.blade.php @@ -17,7 +17,7 @@ Tambah Periode
@if(session()->has('msg')) -
+
@if(session()->get('type') == 'success') @else diff --git a/resources/views/shared/navbar.blade.php b/resources/views/shared/navbar.blade.php index 5580e7f..2489c30 100644 --- a/resources/views/shared/navbar.blade.php +++ b/resources/views/shared/navbar.blade.php @@ -48,7 +48,7 @@ Kuitansi - @if(Auth::user()->role == 'Admin') + @if(Auth::user()->role == 'Admin' || Auth::user()->role == 'SuperAdmin')
@if(session()->has('msg')) -
+ @if(session()->has('msg')) -
+
@if(session()->get('type') == 'success') @else @@ -28,7 +28,7 @@ @endif
- +
@@ -48,14 +48,14 @@ - diff --git a/resources/views/users/form.blade.php b/resources/views/users/form.blade.php index e69de29..3bcba28 100644 --- a/resources/views/users/form.blade.php +++ b/resources/views/users/form.blade.php @@ -0,0 +1,69 @@ +@extends('layouts.app') + +@section('site-name','Sistem Informasi SPP') +@section('page-name', (isset($user) ? 'Ubah Pengguna' : 'Pengguna Baru')) + +@section('content') +
+
+
+
+

@yield('page-name')

+
+
+ @if($errors->any()) +
+ @foreach($errors->all() as $error) + {{ $error }}
+ @endforeach +
+ @endif +
+
+ @csrf +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+@endsection +@section('js') + +@endsection \ No newline at end of file diff --git a/resources/views/users/index.blade.php b/resources/views/users/index.blade.php index e69de29..019b760 100644 --- a/resources/views/users/index.blade.php +++ b/resources/views/users/index.blade.php @@ -0,0 +1,110 @@ +@extends('layouts.app') + +@section('site-name','Sistem Informasi SPP') +@section('page-name','Pengguna') + +@section('content') + +
+
+
+
+

@yield('page-name')

+ Tambah Pengguna +
+ @if(session()->has('msg')) +
+ @if(session()->get('type') == 'success') + + @else + + @endif + {{ session()->get('msg') }} +
+ @endif +
+ +
No. {{ $item->jumlah_idr }} + @if($item->wajib_semua != null)

Wajib Semua

@elseif($item->kelas_id != null)

{{ $item->kelas->nama }} {{ isset($item->kelas->periode) ? ' - '.$item->kelas->periode->nama : '' }}

@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
+ + + + + + + + + + + + @foreach ($users as $index => $item) + + + + + + + + + @endforeach + +
No.NamaEmailTanggalStatus
{{ $index+1 }} + @if(Auth::user()->id == $item->id) + {{ $item->name }} + @else + {{ $item->name }} + @endif + {{ $item->email }}{{ $item->created_at->format('d-m-Y') }}{{ $item->role }} + + + + @if(Auth::user()->id != $item->id) + + + + @endif +
+ @csrf +
+
+
+ +
+
+
+@endsection +@section('js') + +@endsection \ No newline at end of file