0% found this document useful (0 votes)
22 views18 pages

Tutorial Laravel 10 #3 Membuat Model Dan Migration

This tutorial teaches how to create a model and migration in Laravel. It shows how to generate a model and migration using an Artisan command, define the migration, migrate the database, and define the model's fillable fields.

Uploaded by

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

Tutorial Laravel 10 #3 Membuat Model Dan Migration

This tutorial teaches how to create a model and migration in Laravel. It shows how to generate a model and migration using an Artisan command, define the migration, migrate the database, and define the model's fillable fields.

Uploaded by

agus.sidik2022
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Tutorial Laravel 10 #3 : Membuat Model dan Migration — SantriKoding.com — Website Belajar C... https://santrikoding.

com/tutorial-laravel-10-3-membuat-model-dan-migration

.env

.env

DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

1 of 18 1/25/2024, 2:42 PM
Tutorial Laravel 10 #3 : Membuat Model dan Migration — SantriKoding.com — Website Belajar C... https://santrikoding.com/tutorial-laravel-10-3-membuat-model-dan-migration

DB_DATABASE=db_laravel_10
DB_USERNAME=root
DB_PASSWORD=

DB_DATABASE db_laravel_10
DB_PASSWORD

db_laravel_10

php artisan make:model Post -m

Post
-m

2 of 18 1/25/2024, 2:42 PM
Tutorial Laravel 10 #3 : Membuat Model dan Migration — SantriKoding.com — Website Belajar C... https://santrikoding.com/tutorial-laravel-10-3-membuat-model-dan-migration

• app/Models/Post.php
• database/migrations/2023_02_14_232119_create_posts_table.php

database/migrations
/2023_02_14_232119_create_posts_table.php function up

public function up(): void


{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('image');
$table->string('title');
$table->text('content');
$table->timestamps();
});
}

image string

title string

content text

insert update delete

app/Models/Post.php

3 of 18 1/25/2024, 2:42 PM
Tutorial Laravel 10 #3 : Membuat Model dan Migration — SantriKoding.com — Website Belajar C... https://santrikoding.com/tutorial-laravel-10-3-membuat-model-dan-migration

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Post extends Model


{
use HasFactory;

/**
* fillable
*
* @var array
*/
protected $fillable = [
'image',
'title',
'content',
];
}

$fillable

migrate

php artisan migrate

4 of 18 1/25/2024, 2:42 PM
Tutorial Laravel 10 #3 : Membuat Model dan Migration — SantriKoding.com — Website Belajar C... https://santrikoding.com/tutorial-laravel-10-3-membuat-model-dan-migration

5 of 18 1/25/2024, 2:42 PM
Tutorial Laravel 10 #3 : Membuat Model dan Migration — SantriKoding.com — Website Belajar C... https://santrikoding.com/tutorial-laravel-10-3-membuat-model-dan-migration

6 of 18 1/25/2024, 2:42 PM
Tutorial Laravel 10 #3 : Membuat Model dan Migration — SantriKoding.com — Website Belajar C... https://santrikoding.com/tutorial-laravel-10-3-membuat-model-dan-migration

7 of 18 1/25/2024, 2:42 PM
Tutorial Laravel 10 #3 : Membuat Model dan Migration — SantriKoding.com — Website Belajar C... https://santrikoding.com/tutorial-laravel-10-3-membuat-model-dan-migration

8 of 18 1/25/2024, 2:42 PM
Tutorial Laravel 10 #3 : Membuat Model dan Migration — SantriKoding.com — Website Belajar C... https://santrikoding.com/tutorial-laravel-10-3-membuat-model-dan-migration

9 of 18 1/25/2024, 2:42 PM
Tutorial Laravel 10 #3 : Membuat Model dan Migration — SantriKoding.com — Website Belajar C... https://santrikoding.com/tutorial-laravel-10-3-membuat-model-dan-migration

10 of 18 1/25/2024, 2:42 PM
Tutorial Laravel 10 #3 : Membuat Model dan Migration — SantriKoding.com — Website Belajar C... https://santrikoding.com/tutorial-laravel-10-3-membuat-model-dan-migration

11 of 18 1/25/2024, 2:42 PM
Tutorial Laravel 10 #3 : Membuat Model dan Migration — SantriKoding.com — Website Belajar C... https://santrikoding.com/tutorial-laravel-10-3-membuat-model-dan-migration

12 of 18 1/25/2024, 2:42 PM
Tutorial Laravel 10 #3 : Membuat Model dan Migration — SantriKoding.com — Website Belajar C... https://santrikoding.com/tutorial-laravel-10-3-membuat-model-dan-migration

13 of 18 1/25/2024, 2:42 PM
Tutorial Laravel 10 #3 : Membuat Model dan Migration — SantriKoding.com — Website Belajar C... https://santrikoding.com/tutorial-laravel-10-3-membuat-model-dan-migration

14 of 18 1/25/2024, 2:42 PM
Tutorial Laravel 10 #3 : Membuat Model dan Migration — SantriKoding.com — Website Belajar C... https://santrikoding.com/tutorial-laravel-10-3-membuat-model-dan-migration

15 of 18 1/25/2024, 2:42 PM
Tutorial Laravel 10 #3 : Membuat Model dan Migration — SantriKoding.com — Website Belajar C... https://santrikoding.com/tutorial-laravel-10-3-membuat-model-dan-migration

16 of 18 1/25/2024, 2:42 PM
Tutorial Laravel 10 #3 : Membuat Model dan Migration — SantriKoding.com — Website Belajar C... https://santrikoding.com/tutorial-laravel-10-3-membuat-model-dan-migration

17 of 18 1/25/2024, 2:42 PM
Tutorial Laravel 10 #3 : Membuat Model dan Migration — SantriKoding.com — Website Belajar C... https://santrikoding.com/tutorial-laravel-10-3-membuat-model-dan-migration

18 of 18 1/25/2024, 2:42 PM

You might also like