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