반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 전자소송
- 코로나
- 소액임금체불
- 사업자계좌
- Bootstrap
- Eclipse
- 당사자표시정정신청서
- 코로나19
- Python
- auth
- Java
- win32
- 인민공원
- 이더리움
- php
- cartalyst
- Blade
- reactnative
- 보정명령
- vue
- as후기
- Sentinel
- 개인사업자
- Tutorial
- blockchain
- 체당금
- javascript
- 홈택스
- Laravel
- elasticSearch
Archives
- Today
- Total
그냥 사는 이야기
Laravel 5.3 Blog System - Setup Database 본문
반응형
Setup database
Auth 추가
php artisan make:auth
database/migrations/CreateUsersTable
$table->enum('role',['admin','author','subscriber'])->default('author');
php artisan migrate
database seed 추가
database/seeds/DatabaseSeeder
use App\User;
class DatabaseSeeder extends Seeder
{
public function run()
{
$this->call(UsersTableSeeder::class);
}
}
class UsersTableSeeder extends Seeder
{
public function run()
{
DB::table('users')->delete();
User::create(array(
'name' => 'admin',
'email' => 'admin@example.com',
'password' => bcrypt('111111'),
'role' => 'admin',
));
User::create(array(
'name' => 'kmpak',
'email' => 'kmpak@example.com',
'password' => bcrypt('111111'),
'role' => 'author',
));
User::create(array(
'name' => 'example',
'email' => 'example@example.com',
'password' => bcrypt('111111'),
'role' => 'subscriber',
));
}
}
post, comment 테이블 추가
php artisan make:migration create_posts_table
php artisan make:migration create_comments_table
database/migrations/CreatePostsTable
class CreatePostsTable extends Migration
{
public function up()
{
// posts table
Schema::create('posts', function(Blueprint $table) {
$table->increments('id'); // table Id's
$table -> integer('author_id')->unsigned()->default(0);
$table->foreign('author_id')
->references('id')->on('users')
->onDelete('cascade');
$table->string('title')->unique();
$table->string('description'); // for meta description
$table->text('body'); // our posts
$table->string('slug')->unique();
$table->string('images');
$table->boolean('active');
$table->timestamps();
});
}
public function down()
{
Schema::drop('posts');
}
}
database/migrations/CreateCommentsTable
class CreateCommentsTable extends Migration
{
public function up()
{
// comments table
Schema::create('comments', function(Blueprint $table) {
$table->increments('id');
$table -> integer('on_post')->unsigned()->default(0);
$table->foreign('on_post')
->references('id')->on('posts')
->onDelete('cascade');
$table -> integer('from_user')->unsigned()->default(0);
$table->foreign('from_user')
->references('id')->on('users')
->onDelete('cascade');
$table->text('body'); // our comments
$table->timestamps();
});
}
public function down()
{
// delete comments table
Schema::drop('comments');
}
}
Post, Comment Model & Seed 생성
php artisan make:model Post
php artisan make:model Comment
php artisan make:seeder PostsTableSeeder
php artisan make:seeder CommentsTableSeeder
database/seeds/PostsTableSeeder
use App\Post;
...
public function run()
{
DB::table('posts')->delete();
Post::create(array(
'author_id' => 2,
'title' => 'Hello World',
'description' => 'My First Post',
'body' => 'The most interesting function is show since the actual contents of the sequential file are generated here.
가장 재밌는 함수는 show다. 왜냐면 sequential file의 실제 내용이 만들어지기 때문이다.
For the sake of illustration, I present a slightly simplified version that abstracts some of the difficulties
associated with kprobes that would detract from the seq_file issues:
illustration 목적을 위해, 약간 간소화된 버전을 표현한다. kprobes와 연관된 어려운 것들 중 일부를 추상화 했다. seq_file 이슈에서 주의를 딴데로 돌리는 것.',
'slug' => 'my-first-post',
'images' => 'post-bg.jpg',
'active' => '1',
));
Post::create(array(
'author_id' => 2,
'title' => 'Extended Attributes and Access Control Lists',
'description' => 'my next post',
'body' => 'Many filesystems provide features that extend the standard functionality offered by the VFS layer.',
'slug' => 'my-next-post',
'images' => 'post-sample-image.jpg',
'active' => '1',
));
}
database/seeds/CommentsTableSeeder
use App\Comment;
...
public function run()
{
DB::table('comments')->delete();
Comment::create(array(
'on_post' => 1,
'from_user' => 2,
'body' => '우와아 직이네요',
));
}
database/seeds/DatabaseSeeder
...
public function run()
{
$this->call(UsersTableSeeder::class);
$this->call(PostsTableSeeder::class);
$this->call(CommentsTableSeeder::class);
}
database refresh
php artisan migrate:refresh --seed
'Development > Web' 카테고리의 다른 글
Laravel 5.3 Blog System - Bootstrap theme view (0) | 2020.01.22 |
---|---|
Laravel 5.3 Blog System - Post And Comments (2) | 2020.01.22 |
Laravel 5.3 Sentinel - Visitors & Manager (0) | 2020.01.21 |
Laravel 5.3 Sentinel - Restricting Access According to Roles (0) | 2020.01.21 |
Laravel 5.3 Sentinel - Roles (0) | 2020.01.21 |
Comments