You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					50 lines
				
				1.2 KiB
			
		
		
			
		
	
	
					50 lines
				
				1.2 KiB
			| 
								 
											2 years ago
										 
									 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								namespace App\Models;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								use App\Scopes\RestaurantScope;
							 | 
						||
| 
								 | 
							
								use App\Scopes\ZoneScope;
							 | 
						||
| 
								 | 
							
								use Illuminate\Database\Eloquent\Model;
							 | 
						||
| 
								 | 
							
								use Illuminate\Database\Eloquent\Builder;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class AddOn extends Model
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    protected $casts = [
							 | 
						||
| 
								 | 
							
								        'price' => 'float',
							 | 
						||
| 
								 | 
							
								        'restaurant_id' => 'integer',
							 | 
						||
| 
								 | 
							
								        'status' => 'integer',
							 | 
						||
| 
								 | 
							
								        'created_at' => 'datetime',
							 | 
						||
| 
								 | 
							
								        'updated_at' => 'datetime'
							 | 
						||
| 
								 | 
							
								    ];
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public function translations()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        return $this->morphMany(Translation::class, 'translationable');
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public function scopeActive($query)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        return $query->where('status', 1);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public function restaurant()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        return $this->belongsTo(Restaurant::class);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    protected static function booted()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        if(auth('vendor')->check() || auth('vendor_employee')->check())
							 | 
						||
| 
								 | 
							
								        {
							 | 
						||
| 
								 | 
							
								            static::addGlobalScope(new RestaurantScope);
							 | 
						||
| 
								 | 
							
								        } 
							 | 
						||
| 
								 | 
							
								        static::addGlobalScope(new ZoneScope);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        static::addGlobalScope('translate', function (Builder $builder) {
							 | 
						||
| 
								 | 
							
								            $builder->with(['translations' => function($query){
							 | 
						||
| 
								 | 
							
								                return $query->where('locale', app()->getLocale());
							 | 
						||
| 
								 | 
							
								            }]);
							 | 
						||
| 
								 | 
							
								        });
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |