Skip to content

Commit

Permalink
feat: add filament resource, http api
Browse files Browse the repository at this point in the history
  • Loading branch information
daurensky committed Mar 10, 2024
1 parent 2c96d9c commit e3c8b08
Show file tree
Hide file tree
Showing 19 changed files with 631 additions and 42 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"filament/filament": "^3.0-stable",
"ibecsystems/admin-kit-core": "^3.1",
"illuminate/contracts": "^10.0",
"spatie/laravel-package-tools": "^1.14.0",
"spatie/laravel-data": "^3.2",
"spatie/laravel-data": "^4.2",
"spatie/laravel-json-api-paginate": "^1.13",
"spatie/laravel-package-tools": "^1.14.0",
"spatie/laravel-query-builder": "^5.7",
"spatie/laravel-translatable": "^6.5"
},
Expand Down
13 changes: 10 additions & 3 deletions database/migrations/create_admin_kit_companies_table.php.stub
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration
{
Expand All @@ -12,7 +12,14 @@ return new class extends Migration
$table->id();

// add fields
$table->jsonb('title')->default('{}');
$table->jsonb('title');
$table->jsonb('text');

$table->jsonb('history_title')->nullable();
$table->jsonb('history_text')->nullable();

$table->jsonb('mission_title')->nullable();
$table->jsonb('mission_text')->nullable();

$table->timestamps();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration
{
public function up(): void
{
Schema::create('admin_kit_company_histories', function (Blueprint $table) {
$table->id();

// add fields
$table->foreignId('company_id')
->constrained('admin_kit_companies')
->cascadeOnDelete();

$table->jsonb('title')->nullable();
$table->jsonb('text')->nullable();

$table->integer('sort')->nullable();

$table->timestamps();
});
}

public function down(): void
{
Schema::dropIfExists('admin_kit_company_histories');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration
{
public function up(): void
{
Schema::create('admin_kit_company_managers', function (Blueprint $table) {
$table->id();

// add fields
$table->foreignId('company_id')
->constrained('admin_kit_companies')
->cascadeOnDelete();

$table->jsonb('name');
$table->jsonb('bio')->nullable();
$table->jsonb('text')->nullable();

$table->integer('sort')->nullable();

$table->timestamps();
});
}

public function down(): void
{
Schema::dropIfExists('admin_kit_company_managers');
}
};
31 changes: 31 additions & 0 deletions resources/lang/en/companies.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,39 @@

'id' => 'ID',
'title' => 'Title',
'background' => 'Background',
'general' => 'General',
'description' => 'Description',
'history' => 'History',
'mission' => 'Mission',
'attachments' => 'Attachments',

'created_at' => 'Created At',
'updated_at' => 'Updated At',
],

'relations' => [
'managers' => [
'label' => 'Management',
'plural_label' => 'Managements',

'photo' => 'Photo',
'name' => 'Name',
'bio' => 'Bio',
'about_me' => 'About Me',

'created_at' => 'Created At',
],

'histories' => [
'label' => 'History',
'plural_label' => 'Histories',

'date' => 'Date',
'title' => 'Title',
'description' => 'Description',

'created_at' => 'Created At',
],
],
];
36 changes: 33 additions & 3 deletions resources/lang/ru/companies.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,43 @@

return [
'resource' => [
'label' => 'Company',
'plural_label' => 'Companies',
'label' => 'Компания',
'plural_label' => 'Компании',

'id' => 'ID',
'title' => 'Title',
'title' => 'Заголовок',
'background' => 'Фон',
'general' => 'Основное',
'description' => 'Описание',
'history' => 'История',
'mission' => 'Миссия',
'attachments' => 'Вложения',

'created_at' => 'Создан',
'updated_at' => 'Обновлен',
],

'relations' => [
'managers' => [
'label' => 'Руководитель',
'plural_label' => 'Руководство',

'photo' => 'Фото',
'name' => 'Имя',
'bio' => 'Био',
'about_me' => 'Обо мне',

'created_at' => 'Создан',
],

'histories' => [
'label' => 'История',
'plural_label' => 'Истории',

'title' => 'Заголовок',
'description' => 'Описание',

'created_at' => 'Создан',
],
],
];
18 changes: 18 additions & 0 deletions src/Actions/GetCompany.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace AdminKit\Companies\Actions;

use Spatie\LaravelData\Data;
use AdminKit\Companies\Models\Company;
use AdminKit\Companies\UI\API\DTO\CompanyDTO;

class GetCompany
{
public function run(): Data
{
$company = Company::query()
->firstOrFail();

return CompanyDTO::from($company);
}
}
6 changes: 5 additions & 1 deletion src/CompaniesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ public function configurePackage(Package $package): void
->hasConfigFile()
->hasViews()
->hasTranslations()
->hasMigration('create_admin_kit_companies_table')
->hasMigrations([
'create_admin_kit_companies_table',
'create_admin_kit_company_histories_table',
'create_admin_kit_company_managers_table',
])
->hasCommand(CompaniesCommand::class);
}

Expand Down
77 changes: 70 additions & 7 deletions src/Models/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,95 @@

namespace AdminKit\Companies\Models;

use Spatie\MediaLibrary\HasMedia;
use Illuminate\Support\Collection;
use Spatie\Translatable\HasTranslations;
use Spatie\MediaLibrary\InteractsWithMedia;
use AdminKit\Core\Abstracts\Models\AbstractModel;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Spatie\Translatable\HasTranslations;
use AdminKit\Companies\Database\Factories\CompanyFactory;

class Company extends AbstractModel
/**
* @property-read string $title
* @property-read string $text
* @property-read string $background
*
* @property-read string $history_title
* @property-read string $history_text
*
* @property-read string $mission_title
* @property-read string $mission_text
* @property-read Collection $mission_attachments
* @property-read string $mission_background
*
* @property-read History[] $histories
* @property-read Manager[] $managers
*/
class Company extends AbstractModel implements HasMedia
{
use HasFactory;
use HasTranslations;
use InteractsWithMedia;

protected $table = 'admin_kit_companies';

protected $fillable = [
'title',
'text',
'history_title',
'history_text',
'mission_title',
'mission_text',
];

protected $casts = [
//
];

protected $translatable = [
protected array $translatable = [
'title',
'text',
'history_title',
'history_text',
'mission_title',
'mission_text',
];

protected static function newFactory(): CompanyFactory
{
return new CompanyFactory();
}

public function background(): Attribute
{
return Attribute::make(
get: fn () => $this->getFirstMediaUrl('background')
);
}

public function missionAttachments(): Attribute
{
return Attribute::make(
get: fn () => $this->getMedia('mission_attachments.'.app()->getLocale())
->map
->getFullUrl()
);
}

public function missionBackground(): Attribute
{
return Attribute::make(
get: fn () => $this->getFirstMediaUrl('mission_background.'.app()->getLocale())
);
}

public function histories(): HasMany
{
return $this->hasMany(History::class)
->orderBy('sort');
}

public function managers(): HasMany
{
return $this->hasMany(Manager::class)
->orderBy('sort');
}
}
33 changes: 33 additions & 0 deletions src/Models/History.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace AdminKit\Companies\Models;

use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
use Illuminate\Database\Eloquent\Factories\HasFactory;

/**
* @property-read int $company_id
* @property-read ?string $title
* @property-read ?string $text
* @property-read ?string $sort
*/
class History extends Model
{
use HasFactory;
use HasTranslations;

protected $table = 'admin_kit_company_histories';

protected $fillable = [
'company_id',
'title',
'text',
'sort',
];

protected array $translatable = [
'title',
'text',
];
}
Loading

0 comments on commit e3c8b08

Please sign in to comment.