48 lines
1.1 KiB
PHP
48 lines
1.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models\Admin;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Cviebrock\EloquentSluggable\Sluggable;
|
||
|
|
|
||
|
|
class Blog extends Model
|
||
|
|
{
|
||
|
|
use HasFactory, Sluggable;
|
||
|
|
|
||
|
|
protected $table = 'blog';
|
||
|
|
|
||
|
|
protected $fillable = ['blog_title', 'blog_description', 'blog_image', 'tag_id', 'slug'];
|
||
|
|
|
||
|
|
public function tag()
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Tag::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function sluggable(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'slug' => [
|
||
|
|
'source' => 'blog_title',
|
||
|
|
'onUpdate' => true
|
||
|
|
]
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
// const path = 'https://jerichoalternatives.in/public/uploads/blog/images/';
|
||
|
|
|
||
|
|
public function getBlogImageAttribute($value)
|
||
|
|
{
|
||
|
|
// return Blog::path . $value;
|
||
|
|
return imagePath('public/uploads/blog/images/').$value;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getMinutesToReadAttribute(...$value)
|
||
|
|
{
|
||
|
|
$totalWords = str_word_count(implode(" ", $value));
|
||
|
|
$minutesToRead = round($totalWords / 200);
|
||
|
|
|
||
|
|
return (int)max(1, $minutesToRead) . ' Min Read';
|
||
|
|
}
|
||
|
|
}
|