Commit cb3f3dc8 authored by TTS Tran Viet Anh's avatar TTS Tran Viet Anh

update migration

parent 24adea40
...@@ -12,8 +12,13 @@ class Post extends Model ...@@ -12,8 +12,13 @@ class Post extends Model
protected $guarded = []; protected $guarded = [];
public function category() public function postCategory()
{ {
return $this->belongsTo(Category::class); return $this->belongsTo(PostCategory::class);
}
public function user()
{
return $this->belongsTo(User::class);
} }
} }
...@@ -6,14 +6,14 @@ ...@@ -6,14 +6,14 @@
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
class ProductProperty extends Model class PostCategory extends Model
{ {
use HasFactory, SoftDeletes; use HasFactory, SoftDeletes;
protected $guarded = []; protected $guarded = [];
public function product() public function posts()
{ {
return $this->belongsTo(Product::class); return $this->hasMany(Post::class);
} }
} }
...@@ -12,17 +12,13 @@ class Product extends Model ...@@ -12,17 +12,13 @@ class Product extends Model
protected $guarded = []; protected $guarded = [];
public function category() public function productCategory()
{ {
return $this->belongsTo(Category::class); return $this->belongsTo(ProductCategory::class);
} }
public function mediums() public function productAttributes()
{ {
return $this->hasMany(Media::class, 'accessible_id'); return $this->hasMany(ProductAttribute::class);
}
public function productProperties(){
return $this->hasMany(ProductProperty::class);
} }
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
class Media extends Model class ProductAttribute extends Model
{ {
use HasFactory, SoftDeletes; use HasFactory, SoftDeletes;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
class Category extends Model class ProductCategory extends Model
{ {
use HasFactory, SoftDeletes; use HasFactory, SoftDeletes;
...@@ -16,9 +16,4 @@ public function products() ...@@ -16,9 +16,4 @@ public function products()
{ {
return $this->hasMany(Product::class); return $this->hasMany(Product::class);
} }
public function posts()
{
return $this->hasMany(Post::class);
}
} }
...@@ -38,4 +38,9 @@ class User extends Authenticatable ...@@ -38,4 +38,9 @@ class User extends Authenticatable
protected $casts = [ protected $casts = [
'email_verified_at' => 'datetime', 'email_verified_at' => 'datetime',
]; ];
public function posts()
{
return $this->hasMany(Post::class);
}
} }
...@@ -15,13 +15,14 @@ public function up() ...@@ -15,13 +15,14 @@ public function up()
{ {
Schema::create('users', function (Blueprint $table) { Schema::create('users', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('username'); $table->string('username', 50);
$table->string('email')->unique(); $table->string('email', 50)->unique();
$table->string('phone'); $table->string('phone', 20);
$table->string('address'); $table->string('address', 255);
$table->timestamp('email_verified_at')->nullable(); $table->timestamp('email_verified_at')->nullable();
$table->string('password'); $table->string('password');
$table->rememberToken(); $table->rememberToken();
$table->softDeletes();
$table->timestamps(); $table->timestamps();
}); });
} }
......
...@@ -15,14 +15,15 @@ public function up() ...@@ -15,14 +15,15 @@ public function up()
{ {
Schema::create('products', function (Blueprint $table) { Schema::create('products', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('name'); $table->string('name', 50);
$table->string('image', 255);
$table->text('description'); $table->text('description');
$table->decimal('price',8,2); $table->decimal('price', 8, 2);
$table->unsignedInteger('category_id'); $table->unsignedInteger('product_category_id');
$table->unsignedInteger('stock'); $table->unsignedInteger('stock');
$table->unsignedTinyInteger('status'); $table->unsignedTinyInteger('status');
$table->timestamps();
$table->softDeletes(); $table->softDeletes();
$table->timestamps();
}); });
} }
......
...@@ -15,14 +15,14 @@ public function up() ...@@ -15,14 +15,14 @@ public function up()
{ {
Schema::create('posts', function (Blueprint $table) { Schema::create('posts', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('name'); $table->string('title', 255);
$table->text('content'); $table->text('content');
$table->string('author'); $table->unsignedInteger('user_id');
$table->unsignedInteger('category_id'); $table->unsignedInteger('post_category_id');
$table->date('publish_date'); $table->date('publish_date');
$table->unsignedTinyInteger('status'); $table->unsignedTinyInteger('status');
$table->timestamps();
$table->softDeletes(); $table->softDeletes();
$table->timestamps();
}); });
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
class CreateProductPropertiesTable extends Migration class CreateProductAttributesTable extends Migration
{ {
/** /**
* Run the migrations. * Run the migrations.
...@@ -13,14 +13,14 @@ class CreateProductPropertiesTable extends Migration ...@@ -13,14 +13,14 @@ class CreateProductPropertiesTable extends Migration
*/ */
public function up() public function up()
{ {
Schema::create('product_properties', function (Blueprint $table) { Schema::create('product_attributes', function (Blueprint $table) {
$table->id(); $table->id();
$table->unsignedInteger('size'); $table->string('size', 50);
$table->string('color'); $table->string('color', 50);
$table->unsignedInteger('quantity'); $table->unsignedInteger('quantity');
$table->unsignedInteger('product_id'); $table->unsignedInteger('product_id');
$table->timestamps();
$table->softDeletes(); $table->softDeletes();
$table->timestamps();
}); });
} }
...@@ -31,6 +31,6 @@ public function up() ...@@ -31,6 +31,6 @@ public function up()
*/ */
public function down() public function down()
{ {
Schema::dropIfExists('product_properties'); Schema::dropIfExists('product_attributes');
} }
} }
...@@ -15,13 +15,11 @@ public function up() ...@@ -15,13 +15,11 @@ public function up()
{ {
Schema::create('settings', function (Blueprint $table) { Schema::create('settings', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('logo'); $table->string('code', 255);
$table->string('language'); $table->string('name', 255);
$table->string('hotline'); $table->longText('value');
$table->string('email');
$table->string('address');
$table->timestamps();
$table->softDeletes(); $table->softDeletes();
$table->timestamps();
}); });
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
class CreateCategoriesTable extends Migration class CreateProductCategoriesTable extends Migration
{ {
/** /**
* Run the migrations. * Run the migrations.
...@@ -13,12 +13,11 @@ class CreateCategoriesTable extends Migration ...@@ -13,12 +13,11 @@ class CreateCategoriesTable extends Migration
*/ */
public function up() public function up()
{ {
Schema::create('categories', function (Blueprint $table) { Schema::create('product_categories', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('category_type'); $table->string('name', 50);
$table->string('name');
$table->timestamps();
$table->softDeletes(); $table->softDeletes();
$table->timestamps();
}); });
} }
...@@ -29,6 +28,6 @@ public function up() ...@@ -29,6 +28,6 @@ public function up()
*/ */
public function down() public function down()
{ {
Schema::dropIfExists('categories'); Schema::dropIfExists('product_categories');
} }
} }
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
class CreateMediaTable extends Migration class CreatePostCategoriesTable extends Migration
{ {
/** /**
* Run the migrations. * Run the migrations.
...@@ -13,14 +13,11 @@ class CreateMediaTable extends Migration ...@@ -13,14 +13,11 @@ class CreateMediaTable extends Migration
*/ */
public function up() public function up()
{ {
Schema::create('media', function (Blueprint $table) { Schema::create('post_categories', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('media_type'); $table->string('name', 50);
$table->string('accessible');
$table->unsignedInteger('accessible_id');
$table->string('file_path');
$table->timestamps();
$table->softDeletes(); $table->softDeletes();
$table->timestamps();
}); });
} }
...@@ -31,6 +28,6 @@ public function up() ...@@ -31,6 +28,6 @@ public function up()
*/ */
public function down() public function down()
{ {
Schema::dropIfExists('media'); Schema::dropIfExists('post_categories');
} }
} }
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