0% found this document useful (0 votes)
14 views5 pages

Laravel Create Update

The document outlines the steps to implement create and update features in a Laravel application for a Category model. It includes creating routes, controllers, views, and forms for both creating and editing categories, as well as validating input data and displaying the categories in an index view. The instructions detail the necessary code snippets and methods to handle data storage and retrieval effectively.

Uploaded by

Liony
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views5 pages

Laravel Create Update

The document outlines the steps to implement create and update features in a Laravel application for a Category model. It includes creating routes, controllers, views, and forms for both creating and editing categories, as well as validating input data and displaying the categories in an index view. The instructions detail the necessary code snippets and methods to handle data storage and retrieval effectively.

Uploaded by

Liony
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Laravel

- Fitur Create
1. Di route web.php, buat Route untuk create
a.

b. Buat controller CategoryController


c. Buat Model Category
d. Buat folder Category di views dan file create.blade.php

2. Buat form di create.blade.php


a.

3. Pada Model Category.php


a.

4. Pada CategoryController.php
b. Pada Public Function Create{
c. Return view(‘Category.create’); -> Dikembalikan ke views Folder category file
create
d. }
e. Pada Public Function Store{
f. $this->validate($request, [
g. ‘name’ => $request->get(‘name-); -> ‘name’ merupakan fillable yg deprotected
di model sedangkan get->(‘name’) diambil dari form dengan name=”name”
h. Return redirect()->back();
i. ])}
j.

5. Untuk menampilkan data / show data di index


a. Buat file index.blade.php, dan buat form didalamnya

b.
c. Pada public function Index(){
d. $categories = Category::latest()->get();
e. return view('Category.index', compact('categories'));
f. // Fungsi latest() untuk mengurutkan data dari yang terbaru
g. // Fungsi compact() bergua untuk membawa data secara sekaligus tanpa harus
menggunakan with()
h. }

- Fitur Update
1. Buat file edit.blade.php dan buat form
a.

b. Pada public function edit(string $id){


c. $category = Category::find($id);
d. return view ('category.edit', compact('category'));
e. }
f. Pada Public Function update(Request $request, string $id){
g. $this->validate($request, [
h. 'name' => 'required|min:3'
i. ]);
j.
k. $category = Category::find($id);
l. $category->name = $request->get('name');
m. $category->save();
n. return redirect()->route('category.index');
o. }

You might also like