Edit File: DelegateCompany.php
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use App\Traits\Uploadable; use Illuminate\Support\Facades\File; class DelegateCompany extends Model { use HasFactory, Uploadable; protected $fillable =['name','commercial_number','commercial_image','register_link','category_id', 'avatar','city_id','car_type_id','car_model_id','car_license_image','driving_license_image', 'car_front_image','delegation_image','bank_account_owner','bank_name','bank_account_number', 'bank_iban_number','car_numbers','user_id']; /** * The attributes that are mass assignable. * * @var array */ public function user() { return $this->belongsTo( User::class ); } public function category() { return $this->belongsTo( Category::class ); } public function city() { return $this->belongsTo( City::class ); } // public function getDrivingLicensePathAttribute() // { // return asset( 'assets/uploads/driving_license_images/' . $this->driving_license_image ); // } public function getCommercialImagePathAttribute() { return asset( 'assets/uploads/commercial_images/' . $this->commercial_image ); } // public function getDelegationImagePathAttribute() // { // return asset( 'assets/uploads/delegation_images/' . $this->delegation_image ); // } // public function getCarLicenseImagePathAttribute() // { // return asset( 'assets/uploads/car_license_images/' . $this->car_license_image ); // } // public function getCarFrontImagePathAttribute() // { // return asset( 'assets/uploads/car_front_images/' . $this->car_front_image ); // } public function carType() { return $this->belongsTo( Cartype::class ); } public function carModel() { return $this->belongsTo( CarModel::class ); } public function setCommercialImageAttribute($value) { if($value != 'default.png' && $value != null){ $this->attributes['commercial_image'] = $this->uploadFile($value, 'commercial_images', true, 250, null); } } public function setCarLicenseImageAttribute($value) { if($value != 'default.png' && $value != null) { $this->attributes['car_license_image'] = $this->uploadFile($value, 'car_licenses', true, 250, null); } } // public function setDelegationImageAttribute( $value ) // { // if ( $value != 'default.png' ) // { // if ( $this->delegation_image != 'default.png' and $this->delegation_image ) // { // File::delete( public_path( 'assets/uploads/delegation_images/' . $this->delegation_image ) ); // } // $this->attributes[ 'delegation_image' ] = $this->uploadFile( $value, 'delegation_images', true, 250, null ); // } // } // public function setDrivingLicenseAttribute( $value ) // { // if ( $value != 'default.png' ) // { // if ( $this->driving_license_image != 'default.png' and $this->driving_license_image ) // { // File::delete( public_path( 'assets/uploads/driving_license_images/' . $this->driving_license_image ) ); // } // $this->attributes[ 'driving_license_image' ] = $this->uploadFile( $value, 'driving_license_images', true, 250, null ); // } // } public function setCarFrontImageAttribute($value) { if($value != 'default.png' && $value != null) { $this->attributes['car_front_image'] = $this->uploadFile($value, 'car_fronts', true, 250, null); } } public function setDelegationImageAttribute($value) { if($value != 'default.png' && $value != null) { $this->attributes['delegation_image'] = $this->uploadFile($value, 'delegation_images', true, 250, null); } } public function setPersonalImageAttribute($value) { if($value != 'default.png' && $value != null) { $this->attributes['personal_image'] = $this->uploadFile($value, 'users', true, 250, null); } } public function setDrivingLicenseImageAttribute($value) { if($value != 'default.png' && $value != null) { $this->attributes['driving_license_image'] = $this->uploadFile($value, 'driving_licenses', true, 250, null); } } public function setIdentityCardImageAttribute($value) { if($value != 'default.png' && $value != null) { // dd('idi'); $this->attributes['identity_card_image'] = $this->uploadFile($value, 'identity_card_images', true, 250, null); } } public function getDrivingLicenseImagePathAttribute() { $driving_license = $this->attributes['driving_license_image'] == NULL ? 'default.png' : $this->attributes['driving_license_image']; return asset('assets/uploads/driving_licenses/' . $driving_license); } public function getDelegationImagePathAttribute() { $delegation = $this->attributes['delegation_image'] == NULL ? 'default.png' : $this->attributes['delegation_image']; return asset( 'assets/uploads/delegation_images/' . $delegation ); } public function getIdentityCardImagePathAttribute() { $Id = $this->attributes['identity_card_image'] == NULL ? 'default.png' : $this->attributes['identity_card_image']; return asset( 'assets/uploads/identity_card_images/' . $Id ); } public function getCarLicenseImagePathAttribute() { $carLicense = $this->attributes['car_license_image'] == NULL ? 'default.png' : $this->attributes['car_license_image']; return asset( 'assets/uploads/car_licenses/' . $carLicense ); } public function getCarFrontImagePathAttribute() { $carLicense = $this->attributes['car_front_image'] == NULL ? 'default.png' : $this->attributes['car_front_image']; return asset( 'assets/uploads/car_fronts/' . $carLicense); } public function getPersonalImagePathAttribute() { $delegation = $this->attributes['personal_image'] == NULL ? 'default.png' : $this->attributes['personal_image']; return asset( 'assets/uploads/users/' . $delegation ); } }
Back to File Manager