-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPERUBAHAN TUGAS
572 lines (491 loc) · 20.3 KB
/
PERUBAHAN TUGAS
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
Tambahan Tugas
1. Penggunaan jenis navbar yang berbeda pada app.blade.php
<nav class="navbar navbar-expand-lg navbar-dark bg-dark mb-3">
<a class="navbar-brand" href="#">Laravel Pertama</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="/">Home <span class="sr-only"></span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="/friends">Friends</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/familys">Family</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
2. Penggunaan jenis card yang berbeda pada index.blade.php
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">Nama : {{ $friend['nama'] }}</h5>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">Nomor Telepon : {{ $friend['no_telp'] }}</li>
<li class="list-group-item">Alamat : {{ $friend['alamat'] }}</li>
</ul>
<div class="card-body">
<a href="#" class="card-link btn-warning">Edit Friends</a>
<a href="#" class="card-link btn-danger">Delete Friends</a>
</div>
</div>
3. Penambahan Models Familys
Familys.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Familys extends Model
{
use HasFactory;
protected $guarded = ['last_name'];
}
4. Penambahan Route Family pada web.php
Route::resources([
'friends' => App\Http\Controllers\CobaController::class,
'familys' => App\Http\Controllers\FamilysController::class,
'groups' => App\Http\Controllers\GroupsController::class,
]);
5. Pembuatan FamilyControler yang berisi index, create, store, show, edit, update, dan destroy
FamilyControler.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Familys;
class FamilyController extends Controller
{
/* public function index()
{
return 'test berhasil';
}
public function urutan($ke)
{
// memanggil model firends
$friends = Friends::paginate(3);
return view('friend', compact('friends'));
// memakai compact karena memiliki banyak data array. di isi dengan nama variabel yang akan dipanggil
}
public function coba($ke)
{
return view('coba');
// sesuaikan dengan view yang ingin ditampilkan
}
*/
public function index(){
// memanggil model familys
$familys = Familys::orderBy('id', 'desc')->paginate(1);
return view('family.index', compact('familys'));
// memakai compact karena memiliki banyak data array. di isi dengan nama variabel yang akan dipanggil
}
public function create(){
return view('family.create');
}
public function store(Request $request){
// Validate the request...
$request->validate([
'first_name' => 'required|max:255|',
'last_name' => 'required|unique:familys|max:255|',
'number_phone' => 'required|numeric',
'address' => 'required',
'email' => 'required'
]);
$familys = new Familys;
$familys->first_name = $request->first_name;
$familys->last_name = $request->last_name;
$familys->number_phone = $request->number_phone;
$familys->address = $request->address;
$familys->email = $request->email;
$familys->save();
return redirect('/familys');
}
public function show($id)
{
$familys = Familys::where('id', $id)->first();
// dd($familys);
return view('family.show', ['familys' => $familys]);
}
public function edit($id)
{
$familys = Familys::where('id', $id)->first();
// dd($familys);
return view('family.edit', ['familys' => $familys]);
}
public function update(Request $request, $id)
{
$request->validate([
'first_name' => 'required|max:255|',
'last_name' => 'required|unique:familys|max:255|',
'number_phone' => 'required|numeric',
'address' => 'required',
'email' => 'required'
]);
Familys::find($id)->update([
'first_name' => $request->first_name,
'last_name' => $request->last_name,
'number_phone' => $request->number_phone,
'address' => $request->address,
'email' => $request->email
]);
return redirect('/familys');
}
public function destroy($id)
{
Familys::find($id)->delete();
return redirect('/familys');
}
}
6. Penambahan View Index Family
index.blade.php
@extends('layouts.app')
@section('title', 'Family')
<!-- section key, value karena section ini bukan diambil dari file tetapi dari key-->
@section('content')
<a href="/familys/tambah"><button class="card-link btn-primary">Add Family</button></a>
<!-- karena angka yang kita gunakan adalah array dalam array sehingga memerlukan perulangan berupa foreach -->
@foreach ($familys as $family)
<div class="card border-dark mb-3" style="max-width: 20rem;">
<div class="card-header bg-dark text-light">
<b>MY FAMILY</b>
</div>
<div class="card-body bg-dark p-2 text-dark bg-opacity-10">
<a href="/familys/{{$familys['id']}}" class="card-title">Name : {{ $family['first_name'] }} {{ $family['last_name'] }}</a>
<ul class="list-group list-group-flush">
<li class="list-group-item">Number Phone : {{ $family['number_phone'] }}</li>
<li class="list-group-item">Address : {{ $family['address'] }}</li>
<li class="list-group-item">Email : {{ $family['email'] }}</li>
</ul>
<div class="card-body">
<a href="/familys/{{$familys['id']}}/edit"><button class="card-link btn-warning">Edit Family</button></a>
<form action="/familys/{{$familys['id']}}" method="POST">
@csrf
@method('DELETE')
<button class="card-link btn-danger">Delete Family</button>
</form>
</div>
</div>
</div>
@endforeach
<div>
{{ $familys->links() }}
</div>
@endsection
<!-- end section hanya ditulis sekali aja di paling akhir -->
7. Penambahan View Create Family
create.blade.php
@extends('layouts.app')
@section('title', 'Create Family')
<!-- section key, value karena section ini bukan diambil dari file tetapi dari key-->
@section('content')
<form action="/familys" method="POST">
@csrf
<div class="form-row">
<div class="col-md-6 mb-3">
<label for="first_name">First Name</label>
<input type="text" class="form-control is-valid" id="first_name" name="first_name" aria-describedby="first_name" value="{{ old('first_name') }}" required>
@error('first_name')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
<div id="first_nameFeedback" class="valid-feedback">
Your Name Looks good!
</div>
</div>
<div class="col-md-6 mb-3">
<label for="last_name">Last name</label>
<input type="text" class="form-control is-valid" id="last_name" name="last_name" aria-describedby="last_name" value="{{ old('last_name') }}" required>
@error('last_name')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
<div id="last_nameFeedback" class="valid-feedback">
Your Name Looks good!
</div>
</div>
</div>
<div class="form-row">
<div class="col-md-6 mb-3">
<label for="number_phone">Number Phone</label>
<input type="text" class="form-control is-invalid" id="number_phone" name="number_phone" aria-describedby="number_phone" value="{{ old('number_phone') }}" required>
@error('number_phone')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
<div id="number_phoneFeedback" class="invalid-feedback">
Please provide a valid number.
</div>
</div>
<div class="form-row">
<div class="col-md-6 mb-3">
<label for="address">Address</label>
<input type="text" class="form-control is-invalid" id="address" name="address" aria-describedby="address" value="{{ old('address') }}" required>
@error('address')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
<div id="addressFeedback" class="invalid-feedback">
Please provide a valid address.
</div>
</div>
</div>
<div class="form-row">
<div class="col-md-6 mb-3">
<label for="email">Email</label>
<input type="email" class="form-control is-invalid" id="email" name="email" aria-describedby="email" value="{{ old('email') }}" required>
@error('email')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
<div id="emailFeedback" class="invalid-feedback">
Please provide a valid email address.
</div>
</div>
<div class="form-group">
<div class="form-check">
<input class="form-check-input is-invalid" type="checkbox" value="" id="invalidCheck3" aria-describedby="invalidCheck3Feedback" required>
<label class="form-check-label" for="invalidCheck3">
Agree to terms and conditions
</label>
<div id="invalidCheck3Feedback" class="invalid-feedback">
You must agree before submitting.
</div>
</div>
</div>
<button class="btn btn-primary" type="submit">Submit form</button>
</form>
@endsection
<!-- end section hanya ditulis sekali aja di paling akhir -->
8. Penambahan View Show Family
show.blade.php
@extends('layouts.app')
@section('title', 'Family')
<!-- section key, value karena section ini bukan diambil dari file tetapi dari key-->
@section('content')
<!-- karena angka yang kita gunakan adalah array dalam array sehingga memerlukan perulangan berupa foreach -->
<div class="card border-dark mb-3" style="max-width: 30rem;">
<div class="card-header bg-dark text-light">
<b>Family Card</b>
</div>
<div class="card-body bg-dark p-2 text-dark bg-opacity-10">
<h5 class="card-title">First Name : {{ $familys['first_name'] }} {{ $familys['last_name'] }}</h5>
<ul class="list-group list-group-flush">
<li class="list-group-item">Number Phone : {{ $familys['number_phone'] }}</li>
<li class="list-group-item">Address : {{ $familys['address'] }}</li>
<li class="list-group-item">Email : {{ $familys['email'] }}</li>
</ul>
</div>
</div>
@endsection
<!-- end section hanya ditulis sekali aja di paling akhir -->
9. Penambahan View Edit Family
edit.blade.php
@extends('layouts.app')
@section('title', 'Edit Family')
<!-- section key, value karena section ini bukan diambil dari file tetapi dari key-->
@section('content')
<form action="/familys/{{ $familys['id'] }}" method="POST">
@csrf
@method('PUT')
<div class="form-row">
<div class="col-md-6 mb-3">
<label for="first_name">First Name</label>
<input type="text" class="form-control is-valid" id="first_name" name="first_name" aria-describedby="first_name" value="{{ old('first_name') ? old('first_name') : $familys['first_name'] }}" required>
@error('first_name')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
<div id="first_nameFeedback" class="valid-feedback">
Your Name Looks good!
</div>
</div>
</div>
<div class="form-row">
<div class="col-md-6 mb-3">
<label for="last_name">Last Name</label>
<input type="text" class="form-control is-valid" id="last_name" name="last_name" aria-describedby="last_name" value="{{ old('last_name') ? old('last_name') : $familys['last_name'] }}" required>
@error('last_name')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
<div id="last_nameFeedback" class="valid-feedback">
Your Name Looks good!
</div>
</div>
</div>
<div class="form-row">
<div class="col-md-6 mb-3">
<label for="number_phone">Number Phone</label>
<input type="text" class="form-control is-invalid" id="number_phone" name="number_phone" aria-describedby="number_phone" value="{{ old('number_phone') ? old('number_phone') : $familys['number_phone'] }}" required>
@error('number_phone')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
<div id="number_phoneFeedback" class="invalid-feedback">
Please provide a valid number.
</div>
</div>
<div class="form-row">
<div class="col-md-6 mb-3">
<label for="address">Address</label>
<input type="text" class="form-control is-invalid" id="address" name="address" aria-describedby="address" value="{{ old('address') ? old('address') : $familys['address'] }}" required>
@error('address')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
<div id="addressFeedback" class="invalid-feedback">
Please provide a valid address.
</div>
</div>
</div>
<div class="form-row">
<div class="col-md-6 mb-3">
<label for="email">Email</label>
<input type="text" class="form-control is-invalid" id="email" name="email" aria-describedby="email" value="{{ old('email') ? old('email') : $familys['email'] }}" required>
@error('email')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
<div id="emailFeedback" class="invalid-feedback">
Please provide a valid email address.
</div>
</div>
<div class="form-group">
<div class="form-check">
<input class="form-check-input is-invalid" type="checkbox" value="" id="invalidCheck3" aria-describedby="invalidCheck3Feedback" required>
<label class="form-check-label" for="invalidCheck3">
Agree to terms and conditions
</label>
<div id="invalidCheck3Feedback" class="invalid-feedback">
You must agree before submitting.
</div>
</div>
</div>
<button class="btn btn-primary" type="submit">Submit form</button>
</form>
@endsection
<!-- end section hanya ditulis sekali aja di paling akhir -->
10. Penggunaan Paginate yang berbeda
AppServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Pagination\Paginator;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Paginator::useBootstrap();
}
}
11. Penambahan Database Familys
-- Table structure for table `familys`
--
CREATE TABLE `familys` (
`id` int(11) NOT NULL,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
`number_phone` int(15) NOT NULL,
`address` varchar(100) NOT NULL,
`email` varchar(100) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
`updated_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- Dumping data for table `familys`
--
INSERT INTO `familys` (`id`, `first_name`, `last_name`, `number_phone`, `address`, `email`, `created_at`, `updated_at`) VALUES
(1, 'Gow', 'Swei Lie', 839274678, 'Kesambi', 'gow_sweilie@gmail.com', '2021-10-18 19:55:55', '2021-10-18 19:55:55'),
(2, 'Gow', 'Ye Lie', 836742965, 'Kanoman', 'gow_yelie@gmail.com', '2021-10-18 13:53:36', '2021-10-18 13:53:36'),
(3, 'Gow', 'Sin Lie', 847291763, 'Kolektoran', 'gow_sinlie@gmail.com', '2021-10-18 13:58:02', '2021-10-18 13:58:02'),
(4, 'Gow', 'Kim Lie', 849382761, 'Kesambi', 'gow_kimlie@gmail.com', '2021-10-18 14:00:47', '2021-10-18 14:00:47'),
(5, 'Gow', 'Beng Lie', 873619367, 'Kalijaga', 'gow_benglie@gmail.com', '2021-10-18 14:01:55', '2021-10-18 14:01:55'),
(6, 'Gow', 'Chuan Beng', 874624986, 'Kalijaga', 'gow_chuanbeng@gmail.com', '2021-10-18 14:02:34', '2021-10-18 14:02:34'),
(7, 'Gow', 'Sun Lie', 836962579, 'Jakarta', 'gow_sunlie@gmail.com', '2021-10-18 14:03:18', '2021-10-18 14:03:18'),
(8, 'Berthiana', 'Susanthy', 839271683, 'Kalijaga', 'berthiana_susanthy@gmail.com', '2021-10-24 16:05:34', '2021-10-24 16:05:34');
-- Indexes for table `familys`
--
ALTER TABLE `familys`
ADD PRIMARY KEY (`id`),
ADD UNIQUE KEY `last_name` (`last_name`);
--
-- AUTO_INCREMENT for table `familys`
--
ALTER TABLE `familys`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;
11. Mengubah Tampilan Warna Card Pada index.blade.php dan show.blade.php
<div class="card border-dark mb-3" style="max-width: 20rem;">
<div class="card-header bg-dark text-light">
<b>MY FAMILY</b>
</div>
<div class="card-body bg-dark p-2 text-dark bg-opacity-10">
12. Menambah Groups Family
@foreach ($group->familys as $familys)
<li class="list-group-item"> {{$familys->first_name}} {{$familys->last_name}} </li>
@endforeach
13. Menambahkan Tampilan Home
coba.blade.php
<!-- Cara memanggil app.blade.php -->
@extends('layouts.app')
<!-- extends (nama file. nama folder) -->
@section('title', 'Home')
<!-- section (key, value) karena section ini bukan diambil dari file tetapi dari key-->
@section('content')
<!-- section untuk memanggil isi dari yield -->
<?php
//fungsi untuk merubah nama hari menjadi hari indonesia
function hari_ini()
{
switch (date('D')) {
case 'Sun':
$hari = 'Minggu';
break;
case 'Mon':
$hari = 'Senin';
break;
case 'Tue':
$hari = 'Selasa';
break;
case 'Wed':
$hari = 'Rabu';
break;
case 'Thu':
$hari = 'Kamis';
break;
case 'Fri':
$hari = 'Jum\'at';
break;
case 'Sat':
$hari = 'Sabtu';
break;
default:
$hari = 'Hari tidak diketahui';
break;
}
return $hari;
}
//fungsi untuk merubah format tanggal menjadi tanggal indonesia
function tanggal_indo()
{
$bulan = [1 => 'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember'];
$exp = explode('-', date('d-m-Y'));
return $exp[0] . ' ' . $bulan[(int) $exp[1]] . ' ' . $exp[2];
}
?>
<div class="alert alert-info" role="alert">
<p class="mb-0 text-right"><b><i class="fa fa-calendar"></i> <?= hari_ini(); ?>, <?= tanggal_indo(); ?></b></p>
<hr>
<h4 class="alert-heading"><i class="fa fa-info-circle"></i><b>WELCOME TO WEBSITE LARAVEL PERTAMA SAYA</b></h4>
<p class="mb-5" style="font-size: 16px;">Now You Are Login As <b>ANITA INDAH PERMATA SARI</b> With Level <b>ADMIN</b></p>
</div>
@endsection