This commit is contained in:
Daniela 2024-05-31 17:22:00 +03:00
parent f5b95ee256
commit c0744f1ef7
6 changed files with 193 additions and 0 deletions

View file

@ -0,0 +1,86 @@
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\EmailAccountResource\Pages;
use App\Filament\Resources\EmailAccountResource\RelationManagers;
use App\Models\Domain;
use App\Models\EmailAccount;
use Filament\Forms;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class EmailAccountResource extends Resource
{
protected static ?string $model = EmailAccount::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
public static function form(Form $form): Form
{
return $form
->schema([
Select::make('domain_id')
->label('Domain')
->helperText('Missing a domain? Check the Missing a domain? section to find out how you can create one.')
->options(Domain::all()->pluck('domain', 'id'))
->searchable(),
Forms\Components\TextInput::make('username')
->hint(str('[Missing a domain?](/missing-domain)')->inlineMarkdown()->toHtmlString()),
Forms\Components\TextInput::make('password')
->hint(str('[Forgotten your password?](/forgotten-password)')->inlineMarkdown()->toHtmlString())
->password()
->revealable()
->minLength(8)
->maxLength(20),
DatePicker::make('last_login')
->format('d/m/Y'),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('domain'),
TextColumn::make('username'),
TextColumn::make('password'),
TextColumn::make('created_ad'),
])
->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\ListEmailAccounts::route('/'),
'create' => Pages\CreateEmailAccount::route('/create'),
'edit' => Pages\EditEmailAccount::route('/{record}/edit'),
];
}
}

View file

@ -0,0 +1,12 @@
<?php
namespace App\Filament\Resources\EmailAccountResource\Pages;
use App\Filament\Resources\EmailAccountResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;
class CreateEmailAccount extends CreateRecord
{
protected static string $resource = EmailAccountResource::class;
}

View file

@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\EmailAccountResource\Pages;
use App\Filament\Resources\EmailAccountResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
class EditEmailAccount extends EditRecord
{
protected static string $resource = EmailAccountResource::class;
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}

View file

@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\EmailAccountResource\Pages;
use App\Filament\Resources\EmailAccountResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class ListEmailAccounts extends ListRecords
{
protected static string $resource = EmailAccountResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}

View file

@ -0,0 +1,26 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class EmailAccount extends Model
{
use HasFactory;
protected $fillable = [
'domain_id',
'username',
'password',
'last_login',
];
public function domain(): HasOne
{
return $this->hasOne(Domain::class);
}
}

View file

@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('email_accounts', function (Blueprint $table) {
$table->id();
$table->string('domain_id');
$table->string('username');
$table->string('password');
$table->timestamp('last_login')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('email_accounts');
}
};