- 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.
110 lines
2.3 KiB
PHP
110 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 Service extends Model
|
|
{
|
|
use HasFactory, UpdateCustomFields, CreatedUpdatedBy;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*/
|
|
protected $fillable = [
|
|
'title',
|
|
'slug',
|
|
'short_description',
|
|
'description',
|
|
'parent_id',
|
|
'icon_class',
|
|
'icon_image',
|
|
'image',
|
|
'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),
|
|
);
|
|
}
|
|
|
|
protected function iconImage(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn($value) => asset($value),
|
|
);
|
|
}
|
|
|
|
public function children()
|
|
{
|
|
return $this->hasMany(Service::class, 'parent_id');
|
|
}
|
|
|
|
public function parent()
|
|
{
|
|
return $this->belongsTo(Service::class, 'parent_id');
|
|
}
|
|
|
|
public function documents()
|
|
{
|
|
return $this->morphMany(Document::class, 'documentable');
|
|
}
|
|
}
|