Commit 3d6a9a16 authored by TTS Tran Viet Anh's avatar TTS Tran Viet Anh

update mgration 1

parent cb3f3dc8
...@@ -8,6 +8,11 @@ ...@@ -8,6 +8,11 @@
class Post extends Model class Post extends Model
{ {
const STATUS_DRAFT = 1;
const STATUS_PUBLISHED = 2;
const STATUS_FUTURE_PUBLISH = 3;
const STATUS_DELETED = 4;
use HasFactory, SoftDeletes; use HasFactory, SoftDeletes;
protected $guarded = []; protected $guarded = [];
......
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
class PostCategory extends Model class PostCategory extends Model
{ {
const STATUS_ENABLE = 1;
const STATUS_DISABLE = 2;
const STATUS_DELETED = 3;
use HasFactory, SoftDeletes; use HasFactory, SoftDeletes;
protected $guarded = []; protected $guarded = [];
...@@ -16,4 +20,14 @@ public function posts() ...@@ -16,4 +20,14 @@ public function posts()
{ {
return $this->hasMany(Post::class); return $this->hasMany(Post::class);
} }
public function parent()
{
return $this->hasMany(PostCategory::class);
}
public function children()
{
return $this->belongsTo(PostCategory::class, 'parent_id');
}
} }
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
class Product extends Model class Product extends Model
{ {
const STATUS_ENABLE = 1;
const STATUS_DISABLE = 2;
const STATUS_DELETED = 3;
use HasFactory, SoftDeletes; use HasFactory, SoftDeletes;
protected $guarded = []; protected $guarded = [];
......
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
class ProductCategory extends Model class ProductCategory extends Model
{ {
const STATUS_ENABLE = 1;
const STATUS_DISABLE = 2;
const STATUS_DELETED = 3;
use HasFactory, SoftDeletes; use HasFactory, SoftDeletes;
protected $guarded = []; protected $guarded = [];
...@@ -16,4 +20,14 @@ public function products() ...@@ -16,4 +20,14 @@ public function products()
{ {
return $this->hasMany(Product::class); return $this->hasMany(Product::class);
} }
public function parent()
{
return $this->hasMany(ProductCategory::class);
}
public function children()
{
return $this->belongsTo(ProductCategory::class, 'parent_id');
}
} }
...@@ -18,7 +18,7 @@ class User extends Authenticatable ...@@ -18,7 +18,7 @@ class User extends Authenticatable
* *
* @var array<int, string> * @var array<int, string>
*/ */
protected $guard = []; protected $guarded = [];
/** /**
* The attributes that should be hidden for serialization. * The attributes that should be hidden for serialization.
......
...@@ -15,10 +15,10 @@ public function up() ...@@ -15,10 +15,10 @@ public function up()
{ {
Schema::create('users', function (Blueprint $table) { Schema::create('users', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('username', 50); $table->string('name');
$table->string('email', 50)->unique(); $table->string('email')->unique();
$table->string('phone', 20); $table->string('phone');
$table->string('address', 255); $table->string('address');
$table->timestamp('email_verified_at')->nullable(); $table->timestamp('email_verified_at')->nullable();
$table->string('password'); $table->string('password');
$table->rememberToken(); $table->rememberToken();
......
<?php <?php
use App\Models\Product;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
...@@ -15,13 +16,13 @@ public function up() ...@@ -15,13 +16,13 @@ public function up()
{ {
Schema::create('products', function (Blueprint $table) { Schema::create('products', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('name', 50); $table->string('name');
$table->string('image', 255); $table->string('image');
$table->text('description'); $table->text('description');
$table->decimal('price', 8, 2); $table->decimal('price', 8, 2);
$table->unsignedInteger('product_category_id'); $table->unsignedInteger('product_category_id');
$table->unsignedInteger('stock'); $table->unsignedInteger('stock');
$table->unsignedTinyInteger('status'); $table->unsignedTinyInteger('status')->default(Product::STATUS_ENABLE);
$table->softDeletes(); $table->softDeletes();
$table->timestamps(); $table->timestamps();
}); });
......
<?php <?php
use App\Models\Post;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
...@@ -15,12 +16,12 @@ public function up() ...@@ -15,12 +16,12 @@ public function up()
{ {
Schema::create('posts', function (Blueprint $table) { Schema::create('posts', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('title', 255); $table->string('title');
$table->text('content'); $table->text('content')->nullable()->default(null);
$table->unsignedInteger('user_id'); $table->unsignedInteger('user_id');
$table->unsignedInteger('post_category_id'); $table->unsignedInteger('post_category_id');
$table->date('publish_date'); $table->date('publish_date')->nullable();
$table->unsignedTinyInteger('status'); $table->unsignedTinyInteger('status')->default(Post::STATUS_DRAFT);
$table->softDeletes(); $table->softDeletes();
$table->timestamps(); $table->timestamps();
}); });
......
...@@ -15,8 +15,8 @@ public function up() ...@@ -15,8 +15,8 @@ public function up()
{ {
Schema::create('product_attributes', function (Blueprint $table) { Schema::create('product_attributes', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('size', 50); $table->string('size');
$table->string('color', 50); $table->string('color');
$table->unsignedInteger('quantity'); $table->unsignedInteger('quantity');
$table->unsignedInteger('product_id'); $table->unsignedInteger('product_id');
$table->softDeletes(); $table->softDeletes();
......
...@@ -15,8 +15,8 @@ public function up() ...@@ -15,8 +15,8 @@ public function up()
{ {
Schema::create('settings', function (Blueprint $table) { Schema::create('settings', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('code', 255); $table->string('code');
$table->string('name', 255); $table->string('name');
$table->longText('value'); $table->longText('value');
$table->softDeletes(); $table->softDeletes();
$table->timestamps(); $table->timestamps();
......
<?php <?php
use App\Models\ProductCategory;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
...@@ -15,7 +16,11 @@ public function up() ...@@ -15,7 +16,11 @@ public function up()
{ {
Schema::create('product_categories', function (Blueprint $table) { Schema::create('product_categories', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('name', 50); $table->string('name');
$table->string('image');
$table->unsignedInteger('parent_id');
$table->unsignedTinyInteger('status')->default(ProductCategory::STATUS_ENABLE);
$table->unsignedInteger('ordering');
$table->softDeletes(); $table->softDeletes();
$table->timestamps(); $table->timestamps();
}); });
......
<?php <?php
use App\Models\PostCategory;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
...@@ -15,7 +16,11 @@ public function up() ...@@ -15,7 +16,11 @@ public function up()
{ {
Schema::create('post_categories', function (Blueprint $table) { Schema::create('post_categories', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('name', 50); $table->string('name');
$table->string('image');
$table->unsignedInteger('parent_id');
$table->unsignedTinyInteger('status')->default(PostCategory::STATUS_ENABLE);
$table->unsignedInteger('ordering');
$table->softDeletes(); $table->softDeletes();
$table->timestamps(); $table->timestamps();
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment