add usercompany
This commit is contained in:
@@ -24,9 +24,17 @@ class BankResource extends Resource
|
|||||||
{
|
{
|
||||||
return $form
|
return $form
|
||||||
->schema([
|
->schema([
|
||||||
TextInput::make('name'),
|
TextInput::make('name')
|
||||||
TextInput::make('bab'),
|
->required()
|
||||||
TextInput::make('hb'),
|
->unique(),
|
||||||
|
|
||||||
|
TextInput::make('bab')
|
||||||
|
->required()
|
||||||
|
->unique(),
|
||||||
|
|
||||||
|
TextInput::make('hb')
|
||||||
|
->required()
|
||||||
|
->unique(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,6 +69,7 @@ class BankResource extends Resource
|
|||||||
])
|
])
|
||||||
->actions([
|
->actions([
|
||||||
Tables\Actions\EditAction::make(),
|
Tables\Actions\EditAction::make(),
|
||||||
|
Tables\Actions\DeleteAction::make(),
|
||||||
])
|
])
|
||||||
->bulkActions([
|
->bulkActions([
|
||||||
Tables\Actions\BulkActionGroup::make([
|
Tables\Actions\BulkActionGroup::make([
|
||||||
|
|||||||
91
app/Filament/Resources/Company/UserCompanyResource.php
Normal file
91
app/Filament/Resources/Company/UserCompanyResource.php
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Company;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Company\UserCompanyResource\Pages;
|
||||||
|
use App\Modules\UserCompany\Models\UserCompany;
|
||||||
|
use App\Modules\UserCompany\Types\CompanyType;
|
||||||
|
use Filament\Forms\Components\Select;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Forms\Form;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Tables;
|
||||||
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
|
||||||
|
class UserCompanyResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = UserCompany::class;
|
||||||
|
|
||||||
|
protected static ?string $navigationIcon = 'heroicon-o-briefcase';
|
||||||
|
|
||||||
|
public static function form(Form $form): Form
|
||||||
|
{
|
||||||
|
return $form
|
||||||
|
->schema([
|
||||||
|
Select::make('company_type')
|
||||||
|
->label('Kompaniýa görnüşi')
|
||||||
|
->native(false)
|
||||||
|
->options(CompanyType::options())
|
||||||
|
->default(CompanyType::default())
|
||||||
|
->required(),
|
||||||
|
|
||||||
|
TextInput::make('ssb')
|
||||||
|
->label('Şahsy salgyt belgisi')
|
||||||
|
->unique(ignoreRecord: true)
|
||||||
|
->required(),
|
||||||
|
|
||||||
|
TextInput::make('hb')
|
||||||
|
->label('HB')
|
||||||
|
->unique(ignoreRecord: true)
|
||||||
|
->required(),
|
||||||
|
|
||||||
|
Select::make('bank_id')
|
||||||
|
->relationship(name: 'bank', titleAttribute: 'name')
|
||||||
|
->searchable()
|
||||||
|
->preload()
|
||||||
|
->required(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->columns([
|
||||||
|
TextColumn::make('company_type')
|
||||||
|
->badge()
|
||||||
|
->formatStateUsing(fn (string $state): string => CompanyType::options()[$state])
|
||||||
|
->color(fn (string $state): string => CompanyType::statusClass($state)),
|
||||||
|
// 'ssb'
|
||||||
|
// 'hb'
|
||||||
|
// 'bank_id'
|
||||||
|
])
|
||||||
|
->filters([
|
||||||
|
//
|
||||||
|
])
|
||||||
|
->actions([
|
||||||
|
Tables\Actions\EditAction::make(),
|
||||||
|
])
|
||||||
|
->bulkActions([
|
||||||
|
Tables\Actions\BulkActionGroup::make([
|
||||||
|
Tables\Actions\DeleteBulkAction::make(),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRelations(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => Pages\ListUserCompanies::route('/'),
|
||||||
|
'create' => Pages\CreateUserCompany::route('/create'),
|
||||||
|
'edit' => Pages\EditUserCompany::route('/{record}/edit'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Company\UserCompanyResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Company\UserCompanyResource;
|
||||||
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
|
class CreateUserCompany extends CreateRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = UserCompanyResource::class;
|
||||||
|
|
||||||
|
protected function mutateFormDataBeforeCreate(array $data): array
|
||||||
|
{
|
||||||
|
$data['user_id'] = auth('web')->id();
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Company\UserCompanyResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Company\UserCompanyResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
|
||||||
|
class EditUserCompany extends EditRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = UserCompanyResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\DeleteAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Company\UserCompanyResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Company\UserCompanyResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
class ListUserCompanies extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = UserCompanyResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\CreateAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
app/Modules/AppHelpers/.DS_Store
vendored
Normal file
BIN
app/Modules/AppHelpers/.DS_Store
vendored
Normal file
Binary file not shown.
48
app/Modules/AppHelpers/AppHelpersModule.php
Normal file
48
app/Modules/AppHelpers/AppHelpersModule.php
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Modules\AppHelpers;
|
||||||
|
|
||||||
|
use App\Modules\Makeable;
|
||||||
|
use App\Modules\ModuleContract;
|
||||||
|
|
||||||
|
class AppHelpersModule implements ModuleContract
|
||||||
|
{
|
||||||
|
use Makeable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module is enabled
|
||||||
|
*/
|
||||||
|
protected bool $enabled = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if is module enabled
|
||||||
|
*/
|
||||||
|
public function isEnabled(): bool
|
||||||
|
{
|
||||||
|
return $this->enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable module
|
||||||
|
*/
|
||||||
|
public function disable(): void
|
||||||
|
{
|
||||||
|
$this->enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable module
|
||||||
|
*/
|
||||||
|
public function enable(): void
|
||||||
|
{
|
||||||
|
$this->enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if module has a filament resource
|
||||||
|
*/
|
||||||
|
public function hasFilamentResource(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
16
app/Modules/AppHelpers/Enums/HasEnumHelpers.php
Normal file
16
app/Modules/AppHelpers/Enums/HasEnumHelpers.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Modules\AppHelpers\Enums;
|
||||||
|
|
||||||
|
trait HasEnumHelpers
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get values
|
||||||
|
*
|
||||||
|
* @return array<int, string|int>
|
||||||
|
*/
|
||||||
|
public static function values(): array
|
||||||
|
{
|
||||||
|
return array_map(fn ($case) => $case->value, static::cases());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@ return new class extends Migration
|
|||||||
->nullable();
|
->nullable();
|
||||||
|
|
||||||
$table->foreignId('bank_id')->nullable()->constrained('banks')->nullOnDelete();
|
$table->foreignId('bank_id')->nullable()->constrained('banks')->nullOnDelete();
|
||||||
|
$table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
|
||||||
|
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,6 +2,30 @@
|
|||||||
|
|
||||||
namespace App\Modules\UserCompany\Models;
|
namespace App\Modules\UserCompany\Models;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Modules\Bank\Models\Bank;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
class UserCompany extends Model {}
|
class UserCompany extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* User
|
||||||
|
*
|
||||||
|
* @return BelongsTo<User, $this>
|
||||||
|
*/
|
||||||
|
public function user(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bank
|
||||||
|
*
|
||||||
|
* @return BelongsTo<Bank, $this>
|
||||||
|
*/
|
||||||
|
public function bank(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Bank::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
63
app/Modules/UserCompany/Types/CompanyType.php
Normal file
63
app/Modules/UserCompany/Types/CompanyType.php
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Modules\UserCompany\Types;
|
||||||
|
|
||||||
|
use App\Modules\AppHelpers\Enums\HasEnumHelpers;
|
||||||
|
|
||||||
|
enum CompanyType: string
|
||||||
|
{
|
||||||
|
use HasEnumHelpers;
|
||||||
|
|
||||||
|
/** Telekeçi */
|
||||||
|
case TELEKECI = 'tel';
|
||||||
|
|
||||||
|
/** Hususy kärhana */
|
||||||
|
case HK = 'hk';
|
||||||
|
|
||||||
|
/** Hojalyk jemgyýeti */
|
||||||
|
case HJ = 'hj';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options
|
||||||
|
*
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public static function options(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
self::TELEKECI->value => __('Telekeçi'),
|
||||||
|
self::HK->value => __('Hususy kärhana'),
|
||||||
|
self::HJ->value => __('Hojalyk jemgyýeti'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default option
|
||||||
|
*/
|
||||||
|
public static function default(): string
|
||||||
|
{
|
||||||
|
return self::TELEKECI->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Status classes
|
||||||
|
*
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public static function statusClasses(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
self::TELEKECI->value => 'success',
|
||||||
|
self::HK->value => 'danger',
|
||||||
|
self::HJ->value => 'warning',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get status
|
||||||
|
*/
|
||||||
|
public static function statusClass(?string $key): string
|
||||||
|
{
|
||||||
|
return self::statusClasses()[$key] ?? 'danger';
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user