mirror of
https://github.com/anna-sara/filament_inventory
synced 2025-10-26 23:27:13 +01:00
Type: migration, model, filament
This commit is contained in:
parent
b04c657f05
commit
b6a3d988f1
7 changed files with 204 additions and 0 deletions
77
app/Filament/Resources/TypeResource.php
Normal file
77
app/Filament/Resources/TypeResource.php
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\TypeResource\Pages;
|
||||
use App\Filament\Resources\TypeResource\RelationManagers;
|
||||
use App\Models\Type;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class TypeResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Type::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-bookmark';
|
||||
|
||||
protected static ?string $modelLabel = 'Items types';
|
||||
|
||||
protected static ?string $title = 'Items Types';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label('Namn')
|
||||
->searchable(),
|
||||
])
|
||||
->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\ListTypes::route('/'),
|
||||
'create' => Pages\CreateType::route('/create'),
|
||||
'edit' => Pages\EditType::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function canViewAny(): bool
|
||||
{
|
||||
return auth()->user()->is_admin==true;
|
||||
}
|
||||
}
|
||||
24
app/Filament/Resources/TypeResource/Pages/CreateType.php
Normal file
24
app/Filament/Resources/TypeResource/Pages/CreateType.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\TypeResource\Pages;
|
||||
|
||||
use App\Filament\Resources\TypeResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateType extends CreateRecord
|
||||
{
|
||||
protected static string $resource = TypeResource::class;
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$data['user_id'] = auth()->id();
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
24
app/Filament/Resources/TypeResource/Pages/EditType.php
Normal file
24
app/Filament/Resources/TypeResource/Pages/EditType.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\TypeResource\Pages;
|
||||
|
||||
use App\Filament\Resources\TypeResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditType extends EditRecord
|
||||
{
|
||||
protected static string $resource = TypeResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
}
|
||||
19
app/Filament/Resources/TypeResource/Pages/ListTypes.php
Normal file
19
app/Filament/Resources/TypeResource/Pages/ListTypes.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\TypeResource\Pages;
|
||||
|
||||
use App\Filament\Resources\TypeResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListTypes extends ListRecords
|
||||
{
|
||||
protected static string $resource = TypeResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
10
app/Http/Controllers/TypeController.php
Normal file
10
app/Http/Controllers/TypeController.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TypeController extends Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
22
app/Models/Type.php
Normal file
22
app/Models/Type.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
use App\Models\Item;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Type extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name'
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the items for the type.
|
||||
*/
|
||||
public function item(): HasMany
|
||||
{
|
||||
return $this->hasMany(Item::class);
|
||||
}
|
||||
}
|
||||
28
database/migrations/2025_01_15_182450_create_types_table.php
Normal file
28
database/migrations/2025_01_15_182450_create_types_table.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?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('types', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name')->required();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('types');
|
||||
}
|
||||
};
|
||||
Loading…
Reference in a new issue