Files
new_raffles/Modules/CCMS/app/Models/Country.php
Subash efa9231391 feat: Implement Document Module with Dropzone file upload functionality
- Added DocumentController for handling document uploads and management.
- Created Document model with necessary attributes and relationships.
- Implemented DocumentService for business logic related to documents.
- Set up routes for document management in both web and API contexts.
- Developed views for document upload using Dropzone for file handling.
- Included necessary assets and styles for the Document module.
- Created migration for documents table with appropriate fields.
- Added configuration and service provider for the Document module.
2025-08-01 18:00:15 +05:45

106 lines
2.3 KiB
PHP

<?php
namespace Modules\CCMS\Models;
use App\Traits\CreatedUpdatedBy;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Modules\CCMS\Traits\UpdateCustomFields;
use Modules\Document\Models\Document;
class Country extends Model
{
use HasFactory, UpdateCustomFields, CreatedUpdatedBy;
/**
* The attributes that are mass assignable.
*/
protected $fillable = [
'title',
'slug',
'short_description',
'description',
'image',
'parent_id',
'images',
'custom',
'banner',
'meta_title',
'meta_description',
'meta_keywords',
'sidebar_title',
'sidebar_content',
'sidebar_image',
'button_text',
'button_url',
'button_target',
'status',
'createdby',
'updatedby',
'order',
];
protected function casts(): array
{
return [
'custom' => 'array',
];
}
protected function images(): Attribute
{
return Attribute::make(
get: function ($value) {
if (empty($value)) {
return [];
}
$parts = explode(',', $value);
return array_map(fn($part) => asset(trim($part)), $parts);
}
);
}
protected function image(): Attribute
{
return Attribute::make(
get: fn($value) => asset($value),
);
}
protected function banner(): Attribute
{
return Attribute::make(
get: fn($value) => asset($value),
);
}
protected function sidebarImage(): Attribute
{
return Attribute::make(
get: fn($value) => asset($value),
);
}
public function institutions()
{
return $this->hasMany(Institution::class, 'country_id');
}
public function parent()
{
return $this->belongsTo(Country::class, 'parent_id');
}
public function children()
{
return $this->hasMany(Country::class, 'parent_id');
}
public function documents()
{
return $this->morphMany(Document::class, 'documentable');
}
}