Workshop นี้เป็นส่วนหนึ่งของคอร์ส สอนทำระบบแจ้งซ่อมออนไลน์ Laravel
คอร์สเรียนออนไลน์ สอนทำระบบแจ้งซ่อม ราคา 999 บาท จะได้ Template ตั้งต้น สอนทำเต็มระบบ
- user.blade.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
@extends('layouts.master') @section('title') @lang('User') @endsection @section('content') @component('common-components.breadcrumb') @slot('pagetitle') Admin @endslot @slot('title') User List @endslot @endcomponent <div class="row"> <div class="col-lg-12"> <div class="card"> <div class="card-body"> <div class="row mb-2"> <div class="col-md-6"> <div class="mb-3"> <a href="javascript:void(0);" onclick="openModal()" class="btn btn-success waves-effect waves-light"><i class="mdi mdi-plus me-1"></i>สมาชิก</a> </div> </div> <div class="col-md-6"> <div class="form-inline float-md-end mb-3"> <div class="search-box ms-2"> <div class="position-relative"> <form action="" id="search"> <input type="text" class="form-control rounded bg-light border-0" name="search" placeholder="Search..."> <i class="mdi mdi-magnify search-icon"></i> </form> </div> </div> </div> </div> </div> <!-- end row --> <div class="table-responsive mb-4"> <table class="table table-centered table-nowrap mb-0" id="userTable"> <thead> <tr> <th scope="col">ID</th> <th scope="col">ชื่อ-นามสกุล</th> <th scope="col">อีเมล์</th> <th scope="col">เบอร์โทร</th> <th scope="col">ตำแหน่ง</th> <th scope="col">แผนก</th> <th scope="col">สิทธิ์</th> <th scope="col" style="width: 200px;">แก้ไข/ลบ</th> </tr> </thead> @foreach($data as $item) <tr> <td>{{$item->id}}</td> <td><img src="{{ url('storage/images/'.$item->image) }}" alt=""class="avatar-xs rounded-circle me-2"> {{$item->firstname}} {{$item->lastname}}</td> <td>{{$item->email}}</td> <td>{{$item->mobile}}</td> <td>{{$item->position_name}}</td> <td>{{$item->dep_name}}</td> <td>{{$item->level_name}}</td> <td> <ul class="list-inline mb-0"> <li class="list-inline-item"> <a href="javascript:void(0);" class="px-2 text-primary" onclick="editModal(this)" data-id="{{$item->id}}" data-email="{{$item->email}}" data-password="{{$item->password}}" data-first-name="{{$item->firstname}}" data-last-name="{{$item->lastname}}" data-mobile="{{$item->mobile}}" data-p-id="{{$item->p_id}}" data-dep-id="{{$item->dep_id}}" data-level-id="{{$item->level_id}}" > <i class="uil uil-pen font-size-18"> </i></a> </li> <li class="list-inline-item"> <a href="javascript:void(0);" onclick="DeleteModal(this)" data-id="{{$item->id}}" data-first-name="{{$item->firstname}}" data-last-name="{{$item->lastname}}" class="px-2 text-danger"><i class="uil uil-trash-alt font-size-18"></i></a> </li> </ul> </td> </tr> @endforeach </table> </div> <style> .form-control { border: 1px solid black; } </style> <div class="modal fade" tabindex="-1" id="exampleModal"> <form action="" id="saveData"> <div class="modal-dialog modal-lg"> <!-- Set to large modal --> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">จัดการข้อมูลสมาชิก</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <!-- Row 1: Email and Password --> <div class="row mt-1"> <div class="col-6"> <label for="email" class="col-form-label">อีเมล:</label> <input type="email" name="email" id="email" class="form-control" placeholder="กรอกอีเมล" required> </div> <div class="col-6" id="password-input"> <label for="password" class="col-form-label">รหัสผ่าน:</label> <input type="password" name="password" id="password" class="form-control" placeholder="กรอกรหัสผ่าน"> </div> </div> <!-- Row 4: Name --> <div class="row mt-2"> <div class="col-6"> <label for="firstname" class="col-form-label">ชื่อ:</label> <input type="text" name="firstname" id="firstname" class="form-control" placeholder="กรอกชื่อ"> </div> <div class="col-6"> <label for="lastname" class="col-form-label">นามสกุล:</label> <input type="text" name="lastname" id="lastname" class="form-control" placeholder="กรอกนามสกุล"> </div> </div> <!-- Row 2: Phone Number and Position --> <div class="row mt-2"> <div class="col-6"> <label for="mobile" class="col-form-label">เบอร์โทร:</label> <input type="text" name="mobile" id="mobile" class="form-control" placeholder="กรอกเบอร์โทร"> </div> <div class="col-6"> <label for="position" class="col-form-label">ตำแหน่ง:</label> <select name="p_id" id="position" class="form-control"> <option value="" selected>-เลือกตำแหน่ง-</option> @foreach($positions as $position) <option value="{{ $position->id }}">{{ $position->position_name }}</option> @endforeach </select> </div> </div> <!-- Row 3: Department and Permissions --> <div class="row mt-2"> <div class="col-6"> <label for="department" class="col-form-label">แผนก:</label> <select name="dep_id" id="department" class="form-control"> <option value="" selected>-เลือกแผนก-</option> @foreach($departments as $department) <option value="{{ $department->id }}">{{ $department->dep_name }}</option> @endforeach </select> </div> <div class="col-6"> <label for="userLevel" class="col-form-label">สิทธิ์การใช้งาน:</label> <select name="level_id" id="userLevel" class="form-control"> <option value="" selected>-เลือกสิทธิ์การใช้งาน-</option> @foreach($userLevels as $userLevel) <option value="{{ $userLevel->id }}">{{ $userLevel->level_name }}</option> @endforeach </select> </div> <!-- Image Upload --> <div class="row mt-1"> <div class="col-12"> <label for="image" class="col-form-label">อัปโหลดภาพ:</label> <input type="file" name="image" id="image" class="form-control" accept="image/*"> </div> </div> </div> <input type="hidden" name="id" id="id" class="form-control"> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">ปิด</button> <button type="button" onclick="save()" class="btn btn-primary">บันทึกข้อมูล</button> </div> </div> </div> </form> </div> {!! $data->links('layouts.pagination') !!} </div> </div> </div> </div> <!-- end row --> @endsection @section('script') <script> $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') } }); function openModal() { $('#id').val(null); $('#email').val(null); $('#password').val(null); $('#firstname').val(null); $('#lastname').val(null); $('#mobile').val(null); $('#p_id').val(null); $('#dep_id').val(null); $('#level_id').val(null); $('#exampleModal').modal('show'); } function editModal(element){ $('#password-input').hide(); $('#id').val($(element).data('id')); $('#email').val($(element).data('email')); $('#password').val($(element).data('password')); $('#firstname').val($(element).data('first-name')); $('#lastname').val($(element).data('last-name')); $('#mobile').val($(element).data('mobile')); $('#position').val($(element).data('p-id')); $('#department').val($(element).data('dep-id')); $('#userLevel').val($(element).data('level-id')); $('#exampleModal').modal('show'); } function save(){ id = $('#id').val(); form_data = $('#saveData')[0]; var data = new FormData(form_data); // ตรวจสอบค่าที่ส่งไป console.log(id); if(id == ''){ $.ajax({ type:'POST', enctype: 'multipart/form-data', data : data, contentType: false, processData: false, cache: false, url:'{{url('admins/user/add')}}', success:function(data) { // console.log(data) Swal.fire({ title: data.mgs, html: '', icon: data.icon, timer: 1000, showConfirmButton: false, willClose: () => { window.location.href = ''; clearInterval(timerInterval); } }); } }); }else{ $.ajax({ type: 'POST', enctype: 'multipart/form-data', data: data, contentType: false, processData: false, cache: false, url: '{{url('admins/user/edit')}}', success:function(data) { // console.log(data) Swal.fire({ title: data.mgs, html: '', icon: 'success', timer: 1000, showConfirmButton: false, willClose: () => { window.location.href = ''; clearInterval(timerInterval); } }); } }); } } function DeleteModal(button){ id = $(button).data('id'); name = $(button).data('first-name'); lastname = $(button).data('last-name'); const fullName = `${name} ${lastname}`; Swal.fire({ title : 'ยืนยันการลบข้อมูลหรือไม่ ?', text : `${fullName}`, icon : 'warning', showCancelButton : true, confirmButtonColor : '#3085d6', cancelButtonColor : '#d33', confirmButtonText : 'ยืนยันลบ', cancelButtonText : 'ยกเลิก', }).then((result) => { if (result.isConfirmed) { $.ajax({ url : '{{url('admins/user/del')}}', type :'POST', method: 'DELETE', data : { id : id, }, success: function (data) { Swal.fire({ title: data.mgs, html: '', icon: data.icon, timer: 1000, showConfirmButton: false, willClose: () => { window.location.href = ''; clearInterval(timerInterval); } }); }, error: function (data) { // console.log(response); } }); } }); } $('#search-input').change(function(){ document.getElementById("search").submit(); }) </script> @endsection |
- UserController.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
<?php namespace App\Http\Controllers; use App\Models\User; use App\Models\Position; use App\Models\Department; use App\Models\Level; use Illuminate\Http\Request; use Illuminate\Support\Facades\Hash; class UserController extends Controller { public function __construct() { $this->middleware('auth'); } public function index(Request $request) { $data = User::select('users.*','position.position_name','department.dep_name','user_level.level_name') ->join('position', 'users.p_id', '=','position.id') ->join('department', 'users.dep_id', '=','department.id') ->join('user_level', 'users.level_id', '=','user_level.id'); if (isset($request->search) && $request->search !== '') { $data = $data->where(function($query) use ($request) { $query->where('users.firstname', 'like', '%' . $request->search . '%') ->orWhere('users.lastname', 'like', '%' . $request->search . '%') ->orWhere('users.email', 'like', '%' . $request->search . '%') ->orWhere('position.position_name', 'like', '%' . $request->search . '%') ->orWhere('department.dep_name', 'like', '%' . $request->search . '%') ->orWhere('user_level.level_name', 'like', '%' . $request->search . '%'); }); } $data = $data->orderBy('id', 'DESC')->paginate(10); $positions = Position::select('id','position_name')->get(); $departments = Department::select('id','dep_name')->get(); $userLevels = Level::select('id','level_name')->get(); // return $data; return view('admins/user', compact('data', 'positions', 'departments', 'userLevels')); } public function add(Request $request) { $check = User::where('email', $request->email)->first(); if(isset($check)){ return response() -> json([ 'mgs' => 'อีเมล์มูลซ้ำ กรุณากรอกข้อมูลใหม่', 'icon' => 'error' ]); }else{ if ($request->hasFile('image')) { $file = $request->image; $filenameWithExt = $file->getClientOriginalName(); $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME); $extension = $file->getClientOriginalExtension(); $fileNameToStore = $filename.$extension; $file->storeAs('public/images/', $fileNameToStore); } User::insert([ 'email' => $request->email, 'password' => Hash::make($request->password), 'firstname' => $request->firstname, 'lastname' => $request->lastname, 'mobile' => $request->mobile, 'p_id' => $request->p_id, 'dep_id' => $request->dep_id, 'level_id' => $request->level_id, 'image' => $fileNameToStore, 'created_at' => now(), 'updated_at' => now() ]); } return response()->json([ 'mgs' => 'บันทึกข้อมูลสำเร็จ', 'icon' => 'success' ]); } public function edit(Request $request) { $user = User::where('id', $request->id)->first(); if (!$user) { return response()->json([ 'mgs' => 'ไม่พบข้อมูลผู้ใช้นี้', 'icon' => 'error' ]); } $fileNameToStore = $user->image; if ($request->hasFile('image')) { $file = $request->image; $filenameWithExt = $file->getClientOriginalName(); $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME); $extension = $file->getClientOriginalExtension(); $fileNameToStore = $filename . '.' . $extension; $file->storeAs('public/images/', $fileNameToStore); } $user->email = $request->email; $user->firstname = $request->firstname; $user->lastname = $request->lastname; $user->mobile = $request->mobile; $user->p_id = $request->p_id; $user->dep_id = $request->dep_id; $user->level_id = $request->level_id; $user->image = $fileNameToStore; $user->updated_at = now(); $user->save(); return response()->json([ 'mgs' => 'แก้ไขข้อมูลสำเร็จ', 'icon' => 'success' ]); } public function del(Request $request) { User::where('id', $request->id)->delete(); return response() -> json([ 'mgs' => 'ลบข้อมูลสำเร็จ', 'icon' => 'success' ]); } } |
- profile.blade.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
@extends('layouts.master') @section('title') @lang('User Profile') @endsection @section('content') @component('common-components.breadcrumb') @slot('pagetitle') User @endslot @slot('title') Profile @endslot @endcomponent <style> .form-control { border: 1px solid rgba(0, 0, 0, 0.073); } </style> <div class="row"> <div class="col-lg-12"> <div class="card"> <div class="card-body"> <h5 class="mb-3">ข้อมูลส่วนตัว</h5> <form action="{{ url('admins/update_profile') }}" method="POST" id="saveData" enctype="multipart/form-data"> @csrf <input type="hidden" name="id" id="id" value="{{ $user->id }}"> <!-- Email and Password Row --> <div class="row mt-1"> <div class="col-6"> <label for="email" class="col-form-label">อีเมล:</label> <input type="email" name="email" id="email" class="form-control" value="{{ $user->email }}" required> </div> <div class="col-6"> <label for="password" class="col-form-label">รหัสผ่านใหม่:</label> <input type="password" name="password" id="password" class="form-control" placeholder="กรอกรหัสผ่านใหม่"> </div> </div> <!-- Name Row --> <div class="row mt-2"> <div class="col-6"> <label for="firstname" class="col-form-label">ชื่อ:</label> <input type="text" name="firstname" id="firstname" class="form-control" value="{{ $user->firstname }}"> </div> <div class="col-6"> <label for="lastname" class="col-form-label">นามสกุล:</label> <input type="text" name="lastname" id="lastname" class="form-control" value="{{ $user->lastname }}"> </div> </div> <!-- Phone Number and Position Row --> <div class="row mt-2"> <div class="col-6"> <label for="mobile" class="col-form-label">เบอร์โทร:</label> <input type="text" name="mobile" id="mobile" class="form-control" value="{{ $user->mobile }}"> </div> <div class="col-6"> <label for="position" class="col-form-label">ตำแหน่ง:</label> <select name="p_id" id="position" class="form-control"> <option value="" selected>-เลือกตำแหน่ง-</option> @foreach($positions as $position) <option value="{{ $position->id }}" {{ $user->p_id == $position->id ? 'selected' : '' }}>{{ $position->position_name }}</option> @endforeach </select> </div> </div> <!-- Department and Permissions Row --> <div class="row mt-2"> <div class="col-6"> <label for="department" class="col-form-label">แผนก:</label> <select name="dep_id" id="department" class="form-control"> <option value="" selected>-เลือกแผนก-</option> @foreach($departments as $department) <option value="{{ $department->id }}" {{ $user->dep_id == $department->id ? 'selected' : '' }}>{{ $department->dep_name }}</option> @endforeach </select> </div> <div class="col-6"> <label for="userLevel" class="col-form-label">สิทธิ์การใช้งาน:</label> <select name="level_id" id="userLevel" class="form-control"> <option value="" selected>-เลือกสิทธิ์การใช้งาน-</option> @foreach($userLevels as $userLevel) <option value="{{ $userLevel->id }}" {{ $user->level_id == $userLevel->id ? 'selected' : '' }}>{{ $userLevel->level_name }}</option> @endforeach </select> </div> </div> <!-- Image Upload --> <div class="row mt-2"> <div class="col-12"> <label for="image" class="col-form-label">อัปโหลดภาพ:</label> <input type="file" name="image" id="image" class="form-control" accept="image/*"> </div> </div> <!-- Submit Button --> <div class="row mt-3"> <div class="col-12 text-end"> <button type="submit" class="btn btn-primary">บันทึกการเปลี่ยนแปลง</button> </div> </div> </form> </div> </div> </div> </div> <script src="{{ URL::asset('/assets/libs/sweetalert2/sweetalert2.min.js')}}"></script> <script> @if(session('mgs')) Swal.fire({ title: "{{ session('mgs') }}", html: '', icon: "{{ session('icon') }}", timer: 1000, showConfirmButton: false, willClose: () => { window.location.href = ''; clearInterval(timerInterval); } }); @endif </script> @endsection |
สนใจจ้างพัฒนาระบบ เขียนระบบ
ทำเว็บไซต์ รับสอนเขียนโปรแกรม
inbox มาที่เพจ หรือติดต่อ 098-373-8651
ช่องทางการชำระเงิน
เงินสด หรือ e-banking
ธนาคารกสิกรไทย
เลขบัญชี : 0951168564
ชื่อบัญชี : นายวัยวุฒิ ชุมเมืองปัก