mirror of
https://github.com/anna-sara/filament_inventory
synced 2025-10-26 21:37:14 +01:00
Updated Item: Model, Resource, Migration
This commit is contained in:
parent
5ee8c3c865
commit
eaf954d7ff
5 changed files with 61 additions and 7 deletions
|
|
@ -5,6 +5,7 @@ namespace App\Filament\Resources\ItemResource\Pages;
|
|||
use App\Filament\Resources\ItemResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CreateItem extends CreateRecord
|
||||
{
|
||||
|
|
@ -14,4 +15,16 @@ class CreateItem extends CreateRecord
|
|||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
|
||||
protected function handleRecordCreation(array $data): Model
|
||||
{
|
||||
|
||||
if ($data['type'] == "game")
|
||||
{
|
||||
$data['can_be_loaned'] = true;
|
||||
}
|
||||
|
||||
|
||||
return static::getModel()::create($data);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,13 @@ class EditItem extends EditRecord
|
|||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
|
||||
public function getHeading(): string
|
||||
{
|
||||
return 'Edit: ' . $this->getRecord()->desc;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Models;
|
||||
use App\Models\User;
|
||||
use App\Models\Type;
|
||||
use App\Models\Category;
|
||||
use App\Models\Reserveditem;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
|
@ -19,16 +19,20 @@ class Item extends Model
|
|||
'quantity',
|
||||
'cost',
|
||||
'can_be_loaned',
|
||||
'type_id'
|
||||
'category_id',
|
||||
'players',
|
||||
'play_time',
|
||||
'age',
|
||||
'type'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* Get the type of the item
|
||||
*/
|
||||
public function type(): BelongsTo
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Type::class);
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
|
||||
public function reserveditem()
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ return new class extends Migration
|
|||
$table->string('desc')->nullable();
|
||||
$table->date('acquisition_date')->nullable();
|
||||
$table->string('image')->nullable();
|
||||
$table->integer('type_id')->nullable();
|
||||
$table->integer('category_id')->nullable();
|
||||
$table->integer('quantity')->nullable();
|
||||
$table->string('cost')->nullable();
|
||||
$table->boolean('can_be_loaned')->default(false);
|
||||
|
|
|
|||
34
database/migrations/2025_02_24_120234_add_to_items_table.php
Normal file
34
database/migrations/2025_02_24_120234_add_to_items_table.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?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::table('items', function (Blueprint $table) {
|
||||
$table->string('players')->nullable();
|
||||
$table->string('age')->nullable();
|
||||
$table->string('play_time')->nullable();
|
||||
$table->string('type')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('items', function (Blueprint $table) {
|
||||
$table->dropColumn('players');
|
||||
$table->dropColumn('age');
|
||||
$table->dropColumn('play_time');
|
||||
$table->dropColumn('type');
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Reference in a new issue