Server : nginx/1.18.0 System : Linux localhost 6.14.3-x86_64-linode168 #1 SMP PREEMPT_DYNAMIC Mon Apr 21 19:47:55 EDT 2025 x86_64 User : www-data ( 33) PHP Version : 8.0.16 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/ecommerce/app/Models/ |
<?php
namespace App\Models;
use App\Traits\ActiveStatusTrait;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{ use ActiveStatusTrait;
protected $fillable = ['title','tags','summary','slug','description','photo','quote','post_cat_id','post_tag_id','added_by','status'];
public function cat_info()
{
return $this->hasOne(PostCategory::class, 'id', 'post_cat_id');
}
public function tag_info()
{
return $this->hasOne(PostTag::class, 'id', 'post_tag_id');
}
public function author_info()
{
return $this->hasOne(User::class, 'id', 'added_by');
}
public static function getAllPost()
{
return Post::with(['cat_info','author_info'])->orderBy('id', 'DESC')->paginate(10);
}
// public function get_comments(){
// return $this->hasMany(PostComment::class,'post_id','id');
// }
public static function getPostBySlug($slug)
{
return Post::with(['tag_info','author_info'])->where('slug', $slug)->where('status', 'active')->first();
}
public function comments()
{
return $this->hasMany(PostComment::class)->whereNull('parent_id')->where('status', 'active')->with('user_info')->orderBy('id', 'DESC');
}
public function allComments()
{
return $this->hasMany(PostComment::class)->where('status', 'active');
}
// public static function getProductByCat($slug){
// // dd($slug);
// return Category::with('products')->where('slug',$slug)->first();
// // return Product::where('cat_id',$id)->where('child_cat_id',null)->paginate(10);
// }
// public static function getBlogByCategory($id){
// return Post::where('post_cat_id',$id)->paginate(8);
// }
public static function getBlogByTag($slug)
{
// dd($slug);
return Post::where('tags', $slug)->paginate(8);
}
public static function countActivePost()
{
$data = Post::where('status', 'active')->count();
if ($data) {
return $data;
}
return 0;
}
}