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

add slug

parent 7b963a78
......@@ -5,15 +5,16 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Cviebrock\EloquentSluggable\Sluggable;
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, Sluggable;
protected $guarded = [];
......@@ -31,4 +32,18 @@ public function scopePublished($query)
{
return $query->where('status', Post::STATUS_PUBLISHED);
}
public function scopeOfCategories($query, $cat_ids)
{
return $query->whereIn('post_category_id', $cat_ids);
}
public function sluggable()
{
return [
'slug' => [
'source' => 'title'
]
];
}
}
......@@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Cviebrock\EloquentSluggable\Sluggable;
class PostCategory extends Model
{
......@@ -12,7 +13,7 @@ class PostCategory extends Model
const STATUS_DISABLED = 2;
const STATUS_DELETED = 3;
use HasFactory, SoftDeletes;
use HasFactory, SoftDeletes, Sluggable;
protected $guarded = [];
......@@ -31,8 +32,22 @@ public function children()
return $this->hasMany(PostCategory::class, 'parent_id');
}
public function getIdsAttribute()
{
return collect($this->children->pluck('id'))->prepend($this->id)->all();
}
public function scopeNoParent($query)
{
return $query->whereNull('parent_id');
}
public function sluggable(): array
{
return [
'slug' => [
'source' => 'name'
]
];
}
}
......@@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Cviebrock\EloquentSluggable\Sluggable;
class Product extends Model
{
......@@ -12,7 +13,7 @@ class Product extends Model
const STATUS_DISABLED = 2;
const STATUS_DELETED = 3;
use HasFactory, SoftDeletes;
use HasFactory, SoftDeletes, Sluggable;
protected $guarded = [];
......@@ -35,4 +36,13 @@ public function scopeOfCategories($query, $cat_ids)
{
return $query->whereIn('product_category_id', $cat_ids);
}
public function sluggable()
{
return [
'slug' => [
'source' => 'name'
]
];
}
}
......@@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Cviebrock\EloquentSluggable\Sluggable;
class ProductCategory extends Model
{
......@@ -12,7 +13,7 @@ class ProductCategory extends Model
const STATUS_DISABLE = 2;
const STATUS_DELETED = 3;
use HasFactory, SoftDeletes;
use HasFactory, SoftDeletes, Sluggable;
protected $guarded = [];
......@@ -40,4 +41,13 @@ public function scopeNoParent($query)
{
return $query->whereNull('parent_id');
}
public function sluggable(): array
{
return [
'slug' => [
'source' => 'name'
]
];
}
}
......@@ -23,6 +23,7 @@ public function up()
$table->unsignedInteger('product_category_id');
$table->unsignedInteger('stock');
$table->unsignedTinyInteger('status')->default(Product::STATUS_ENABLED);
$table->string('slug')->nullable();
$table->softDeletes();
$table->timestamps();
});
......
......@@ -23,6 +23,7 @@ public function up()
$table->unsignedInteger('post_category_id');
$table->date('publish_date')->nullable();
$table->unsignedTinyInteger('status')->default(Post::STATUS_DRAFT);
$table->string('slug')->nullable();
$table->softDeletes();
$table->timestamps();
});
......
......@@ -21,6 +21,7 @@ public function up()
$table->unsignedInteger('parent_id')->nullable();
$table->unsignedTinyInteger('status')->default(ProductCategory::STATUS_ENABLED);
$table->unsignedInteger('ordering');
$table->string('slug')->nullable();
$table->softDeletes();
$table->timestamps();
});
......
......@@ -21,6 +21,7 @@ public function up()
$table->unsignedInteger('parent_id')->nullable();
$table->unsignedTinyInteger('status')->default(PostCategory::STATUS_ENABLED);
$table->unsignedInteger('ordering');
$table->string('slug')->nullable();
$table->softDeletes();
$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