Commit 540ee1db authored by Le Dinh Trung's avatar Le Dinh Trung

Merge branch 'feature/make-migration' into 'dev'

Feature/make migration

See merge request !1
parents 60f1c617 3d6a9a16
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Post extends Model
{
const STATUS_DRAFT = 1;
const STATUS_PUBLISHED = 2;
const STATUS_FUTURE_PUBLISH = 3;
const STATUS_DELETED = 4;
use HasFactory, SoftDeletes;
protected $guarded = [];
public function postCategory()
{
return $this->belongsTo(PostCategory::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class PostCategory extends Model
{
const STATUS_ENABLE = 1;
const STATUS_DISABLE = 2;
const STATUS_DELETED = 3;
use HasFactory, SoftDeletes;
protected $guarded = [];
public function posts()
{
return $this->hasMany(Post::class);
}
public function parent()
{
return $this->hasMany(PostCategory::class);
}
public function children()
{
return $this->belongsTo(PostCategory::class, 'parent_id');
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Product extends Model
{
const STATUS_ENABLE = 1;
const STATUS_DISABLE = 2;
const STATUS_DELETED = 3;
use HasFactory, SoftDeletes;
protected $guarded = [];
public function productCategory()
{
return $this->belongsTo(ProductCategory::class);
}
public function productAttributes()
{
return $this->hasMany(ProductAttribute::class);
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class ProductAttribute extends Model
{
use HasFactory, SoftDeletes;
protected $guarded = [];
public function product()
{
return $this->belongsTo(Product::class);
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class ProductCategory extends Model
{
const STATUS_ENABLE = 1;
const STATUS_DISABLE = 2;
const STATUS_DELETED = 3;
use HasFactory, SoftDeletes;
protected $guarded = [];
public function products()
{
return $this->hasMany(Product::class);
}
public function parent()
{
return $this->hasMany(ProductCategory::class);
}
public function children()
{
return $this->belongsTo(ProductCategory::class, 'parent_id');
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Setting extends Model
{
use HasFactory, SoftDeletes;
protected $guarded = [];
}
...@@ -4,24 +4,21 @@ ...@@ -4,24 +4,21 @@
use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens; use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable class User extends Authenticatable
{ {
use HasApiTokens, HasFactory, Notifiable; use HasApiTokens, HasFactory, Notifiable, SoftDeletes;
/** /**
* The attributes that are mass assignable. * The attributes that are mass assignable.
* *
* @var array<int, string> * @var array<int, string>
*/ */
protected $fillable = [ protected $guarded = [];
'name',
'email',
'password',
];
/** /**
* The attributes that should be hidden for serialization. * The attributes that should be hidden for serialization.
...@@ -41,4 +38,9 @@ class User extends Authenticatable ...@@ -41,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);
}
} }
...@@ -17,9 +17,12 @@ public function up() ...@@ -17,9 +17,12 @@ public function up()
$table->id(); $table->id();
$table->string('name'); $table->string('name');
$table->string('email')->unique(); $table->string('email')->unique();
$table->string('phone');
$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();
$table->softDeletes();
$table->timestamps(); $table->timestamps();
}); });
} }
......
<?php
use App\Models\Product;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateProductsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('image');
$table->text('description');
$table->decimal('price', 8, 2);
$table->unsignedInteger('product_category_id');
$table->unsignedInteger('stock');
$table->unsignedTinyInteger('status')->default(Product::STATUS_ENABLE);
$table->softDeletes();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('products');
}
}
<?php
use App\Models\Post;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePostsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->text('content')->nullable()->default(null);
$table->unsignedInteger('user_id');
$table->unsignedInteger('post_category_id');
$table->date('publish_date')->nullable();
$table->unsignedTinyInteger('status')->default(Post::STATUS_DRAFT);
$table->softDeletes();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('posts');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateProductAttributesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('product_attributes', function (Blueprint $table) {
$table->id();
$table->string('size');
$table->string('color');
$table->unsignedInteger('quantity');
$table->unsignedInteger('product_id');
$table->softDeletes();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('product_attributes');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateSettingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('settings', function (Blueprint $table) {
$table->id();
$table->string('code');
$table->string('name');
$table->longText('value');
$table->softDeletes();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('settings');
}
}
<?php
use App\Models\ProductCategory;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateProductCategoriesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('product_categories', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('image');
$table->unsignedInteger('parent_id');
$table->unsignedTinyInteger('status')->default(ProductCategory::STATUS_ENABLE);
$table->unsignedInteger('ordering');
$table->softDeletes();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('product_categories');
}
}
<?php
use App\Models\PostCategory;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePostCategoriesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('post_categories', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('image');
$table->unsignedInteger('parent_id');
$table->unsignedTinyInteger('status')->default(PostCategory::STATUS_ENABLE);
$table->unsignedInteger('ordering');
$table->softDeletes();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
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