Server : Apache System : Linux 145.162.205.92.host.secureserver.net 5.14.0-611.45.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 1 05:56:53 EDT 2026 x86_64 User : tradze ( 1001) PHP Version : 8.1.34 Disable Function : NONE Directory : /home/tradze/public_html/app/Modules/Services/Models/ |
<?php
namespace App\Modules\Services\Models;
use Cviebrock\EloquentSluggable\Sluggable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Storage;
use App\Modules\Schedules\Models\SalonCart;
use App\Modules\Services\Models\SalonCategory;
use App\Modules\Services\Models\SalonServiceTypeImage;
use Illuminate\Support\Facades\Auth;
class SalonCategory extends Model
{
use SoftDeletes;
use Sluggable;
/**
* The database table used by the model.
*
* @var string
*/
protected $table="salon_categories";
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['service_type_id','parent_category_id','user_id','is_massage','name','slug','search_keywords','subtitle','body','image', 'icon', 'is_header', 'is_showed' ,'order_no'];
/**
* Return the sluggable configuration array for this model.
*
* @return array
*/
protected $appends = ['is_cart', 'full_image_url', 'is_level_two_category', 'icon_url', 'image_added_by_salon'];
public function sluggable() : array
{
return [
'slug' => [
'source' => 'name'
]
];
}
public function getImageFileAttribute()
{
$image = '';
if ($this->image){
if (Storage::disk('public_images')->exists($this->image)){
$image = Storage::disk('public_images')->get($this->image);
}
}
return $image;
}
public function getImageUrlFileAttribute()
{
$image = '';
if ($this->image){
if (Storage::disk('public_images')->exists($this->image)){
$image = "images/".$this->image;
}
}
return $image;
}
public function getFullImageUrlAttribute()
{
$image = '';
if ($this->image){
if (Storage::disk('public_images')->exists($this->image)){
$image = url("images/".$this->image);
}
}
return $image;
}
public function getIconFileAttribute()
{
$icon = '';
if ($this->icon){
if (Storage::disk('public_images')->exists($this->icon)){
$icon = Storage::disk('public_images')->get($this->icon);
}
}
return $icon;
}
public function getIconUrlAttribute()
{
$icon = '';
if ($this->icon){
if (Storage::disk('public_images')->exists($this->icon)){
$icon = url("images/".$this->icon);
}
}
return $icon;
}
public function getUrlAttribute()
{
$url = route('services.show',['slug'=>$this->slug]);
return $url;
}
public function duration()
{
return $this->belongsTo('App\Modules\Services\Models\SalonServiceDuration', 'id', 'sub_category_id');
}
public function getIsCartAttribute()
{
$is_cart = false;
$user_id = "";
// return $is_cart;
if (Auth::user()) {
$user_id = Auth::user()->id;
$condition = array(
'subcategory_id' => $this->id,
'user_id' => $user_id,
);
$cart = SalonCart::where($condition)->get();
if ($cart->count()) {
$is_cart = true;
}
return $is_cart;
} else {
return $is_cart;
}
}
public function getImageAddedBySalonAttribute() {
$user_id = "";
if(Auth::user()) {
if(Auth::user()->hasRole('salon')){
$user_id = Auth::user()->id;
$salon_image = SalonServiceTypeImage::where('parent_category_id', $this->id)->where('user_id', $user_id)->first();
if(!empty($salon_image->image)){
if (Storage::disk('public_images')->exists($salon_image->image)){
$image = url("images/".$salon_image->image);
return $image;
}
return "";
} else {
return "";
}
}
return "";
}
return "";
}
public function getIsLevelTwoCategoryAttribute()
{
$is_level_two = false;
$user_id = "";
if(Auth::user()) {
if(Auth::user()->hasRole('salon')){
$user_id = Auth::user()->id;
$subcategory = SalonCategory::where('id', $this->id)->first();
if(!empty($subcategory->parent_category_id)){
$parent_category = SalonCategory::where('id', $subcategory->parent_category_id)->first();
if(!empty($parent_category->parent_category_id)){
$main_category = SalonCategory::where('id', $parent_category->parent_category_id)->first();
if($main_category->parent_category_id == 0) {
$is_level_two = true;
return $is_level_two;
} else {
return $is_level_two;
}
} else {
return $is_level_two;
}
}else {
return $is_level_two;
}
}
return $is_level_two;
}
return $is_level_two;
}
public function subcategory() {
return $this->hasMany('App\Modules\Services\Models\SalonCategory', 'parent_category_id', 'id');
}
public function subsubcategory() {
return $this->hasMany('App\Modules\Services\Models\SalonCategory', 'parent_category_id', 'id');
}
}