todos angelegt
This commit is contained in:
parent
19a62578fb
commit
cf2c953fab
11
app/Filament/Resources/Todos/Pages/CreateTodo.php
Normal file
11
app/Filament/Resources/Todos/Pages/CreateTodo.php
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Todos\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Todos\TodoResource;
|
||||||
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
|
class CreateTodo extends CreateRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = TodoResource::class;
|
||||||
|
}
|
||||||
19
app/Filament/Resources/Todos/Pages/EditTodo.php
Normal file
19
app/Filament/Resources/Todos/Pages/EditTodo.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Todos\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Todos\TodoResource;
|
||||||
|
use Filament\Actions\DeleteAction;
|
||||||
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
|
||||||
|
class EditTodo extends EditRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = TodoResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
DeleteAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/Filament/Resources/Todos/Pages/ListTodos.php
Normal file
19
app/Filament/Resources/Todos/Pages/ListTodos.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Todos\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Todos\TodoResource;
|
||||||
|
use Filament\Actions\CreateAction;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
class ListTodos extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = TodoResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
CreateAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
49
app/Filament/Resources/Todos/Schemas/TodoForm.php
Normal file
49
app/Filament/Resources/Todos/Schemas/TodoForm.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Todos\Schemas;
|
||||||
|
|
||||||
|
use App\Models\Group;
|
||||||
|
use App\Models\User;
|
||||||
|
use Filament\Forms\Components\DatePicker;
|
||||||
|
use Filament\Forms\Components\Hidden;
|
||||||
|
use Filament\Forms\Components\MorphToSelect;
|
||||||
|
use Filament\Forms\Components\RichEditor;
|
||||||
|
use Filament\Forms\Components\RichEditor\RichEditorTool;
|
||||||
|
use Filament\Forms\Components\Select;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Forms\Components\Textarea;
|
||||||
|
use Filament\Forms\Components\Toggle;
|
||||||
|
use Filament\Schemas\Components\Section;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
use Random\Engine\Secure;
|
||||||
|
|
||||||
|
class TodoForm
|
||||||
|
{
|
||||||
|
public static function configure(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return $schema
|
||||||
|
->components([
|
||||||
|
TextInput::make('name')
|
||||||
|
->label('Titel')
|
||||||
|
->required(),
|
||||||
|
Select::make('user.name')->relationship('user', 'name')->label('Benutzer')->hiddenOn(['create'])->disabledOn(['edit']),
|
||||||
|
Hidden::make('user_id')->default(filament()->auth()->user()->id),
|
||||||
|
RichEditor::make('content')
|
||||||
|
->label('Todo')
|
||||||
|
->columnSpanFull(),
|
||||||
|
MorphToSelect::make('todoable')
|
||||||
|
->types([
|
||||||
|
MorphToSelect\Type::make(User::class)->label('Benutzer')->titleAttribute('name'),
|
||||||
|
MorphToSelect\Type::make(Group::class)->label('Gruppe')->titleAttribute('name'),
|
||||||
|
])
|
||||||
|
->label('zugeordnet'),
|
||||||
|
Section::make()->components([
|
||||||
|
DatePicker::make('due_date')->label('Todo-Datum'),
|
||||||
|
Toggle::make('review')->label('Review')->hint('Todo geht nach Erledigung noch mal zum Ersteller'),
|
||||||
|
|
||||||
|
]),
|
||||||
|
DatePicker::make('follow_up')->label('Wiedervorlage/Erinnerung'),
|
||||||
|
DatePicker::make('done_date')->label('Erledigt am')->hiddenOn(['create']),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
57
app/Filament/Resources/Todos/Tables/TodosTable.php
Normal file
57
app/Filament/Resources/Todos/Tables/TodosTable.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Todos\Tables;
|
||||||
|
|
||||||
|
use Filament\Actions\BulkActionGroup;
|
||||||
|
use Filament\Actions\DeleteBulkAction;
|
||||||
|
use Filament\Actions\EditAction;
|
||||||
|
use Filament\Tables\Columns\IconColumn;
|
||||||
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
|
||||||
|
class TodosTable
|
||||||
|
{
|
||||||
|
public static function configure(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->columns([
|
||||||
|
TextColumn::make('created_at')
|
||||||
|
->dateTime()
|
||||||
|
->sortable()
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
TextColumn::make('updated_at')
|
||||||
|
->dateTime()
|
||||||
|
->sortable()
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
TextColumn::make('name')
|
||||||
|
->searchable(),
|
||||||
|
TextColumn::make('user.name')
|
||||||
|
->searchable(),
|
||||||
|
TextColumn::make('todoable.name')
|
||||||
|
->label('Zugewiesen')
|
||||||
|
->searchable(),
|
||||||
|
TextColumn::make('due_date')
|
||||||
|
->date()
|
||||||
|
->sortable(),
|
||||||
|
TextColumn::make('done_date')
|
||||||
|
->date()
|
||||||
|
->sortable(),
|
||||||
|
TextColumn::make('follow_up')
|
||||||
|
->date()
|
||||||
|
->sortable(),
|
||||||
|
IconColumn::make('review')
|
||||||
|
->boolean(),
|
||||||
|
])
|
||||||
|
->filters([
|
||||||
|
//
|
||||||
|
])
|
||||||
|
->recordActions([
|
||||||
|
EditAction::make(),
|
||||||
|
])
|
||||||
|
->toolbarActions([
|
||||||
|
BulkActionGroup::make([
|
||||||
|
DeleteBulkAction::make(),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
50
app/Filament/Resources/Todos/TodoResource.php
Normal file
50
app/Filament/Resources/Todos/TodoResource.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\Todos;
|
||||||
|
|
||||||
|
use App\Filament\Resources\Todos\Pages\CreateTodo;
|
||||||
|
use App\Filament\Resources\Todos\Pages\EditTodo;
|
||||||
|
use App\Filament\Resources\Todos\Pages\ListTodos;
|
||||||
|
use App\Filament\Resources\Todos\Schemas\TodoForm;
|
||||||
|
use App\Filament\Resources\Todos\Tables\TodosTable;
|
||||||
|
use App\Models\Todo;
|
||||||
|
use BackedEnum;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Schemas\Schema;
|
||||||
|
use Filament\Support\Icons\Heroicon;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
|
||||||
|
class TodoResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = Todo::class;
|
||||||
|
|
||||||
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
|
||||||
|
|
||||||
|
protected static ?string $recordTitleAttribute = 'name';
|
||||||
|
|
||||||
|
public static function form(Schema $schema): Schema
|
||||||
|
{
|
||||||
|
return TodoForm::configure($schema);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return TodosTable::configure($table);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRelations(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => ListTodos::route('/'),
|
||||||
|
'create' => CreateTodo::route('/create'),
|
||||||
|
'edit' => EditTodo::route('/{record}/edit'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
23
app/Models/Todo.php
Normal file
23
app/Models/Todo.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||||
|
use Override;
|
||||||
|
|
||||||
|
#[Fillable('name', 'content', 'user_id', 'todoable_type', 'todoable_id', 'due_date', 'done_date', 'follow_up', 'review')]
|
||||||
|
class Todo extends Model
|
||||||
|
{
|
||||||
|
public function todoable(): MorphTo
|
||||||
|
{
|
||||||
|
return $this->morphTo();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function user(): BelongsTo {
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -11,6 +11,7 @@ use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|||||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
|
|
||||||
@ -49,6 +50,11 @@ class User extends Authenticatable implements FilamentUser
|
|||||||
return $this->belongsToMany(Group::class);
|
return $this->belongsToMany(Group::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function todos(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Todo::class);
|
||||||
|
}
|
||||||
|
|
||||||
public function hasRole(string $role): bool
|
public function hasRole(string $role): bool
|
||||||
{
|
{
|
||||||
return in_array($role, $this->roles()->pluck('name')->toArray());
|
return in_array($role, $this->roles()->pluck('name')->toArray());
|
||||||
|
|||||||
37
database/migrations/2026_06_02_171154_create_todos_table.php
Normal file
37
database/migrations/2026_06_02_171154_create_todos_table.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
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('todos', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->timestamps();
|
||||||
|
$table->string('name');
|
||||||
|
$table->text('content')->nullable();
|
||||||
|
$table->foreignIdFor(User::class);
|
||||||
|
$table->string('todoable_type')->nullable();
|
||||||
|
$table->integer('todoable_id')->nullable();
|
||||||
|
$table->date('due_date')->nullable();
|
||||||
|
$table->date('done_date')->nullable();
|
||||||
|
$table->date('follow_up')->nullable();
|
||||||
|
$table->boolean('review')->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('todos');
|
||||||
|
}
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user