Orderstatus als Model, nicht Enum

This commit is contained in:
Alexander Gabriel 2026-02-17 00:26:01 +01:00
parent 20767d392f
commit 267872406d
6 changed files with 133 additions and 12 deletions

View File

@ -2,7 +2,7 @@
namespace App\Filament\Resources\Orders\Schemas; namespace App\Filament\Resources\Orders\Schemas;
use App\Orderstatus; use App\Models\Orderstatus;
use Filament\Actions\Action; use Filament\Actions\Action;
use Filament\Forms\Components\DateTimePicker; use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Select; use Filament\Forms\Components\Select;
@ -25,7 +25,7 @@ class OrderForm
->required() ->required()
->numeric() ->numeric()
->default(1), ->default(1),
Select::make("orderstatus")->options(Orderstatus::class)->visibleOn(["edit"]), Select::make("orderstatus_id")->relationship("orderstatus", "name")->visibleOn(["edit"]),
DateTimePicker::make('orderdatetime')->visibleOn(["edit", "view"]), DateTimePicker::make('orderdatetime')->visibleOn(["edit", "view"]),
Select::make('user_id') Select::make('user_id')
->relationship("user", "name") ->relationship("user", "name")

View File

@ -2,7 +2,7 @@
namespace App\Filament\Resources\Orders\Tables; namespace App\Filament\Resources\Orders\Tables;
use App\Orderstatus; use App\Models\Orderstatus;
use Filament\Actions\Action; use Filament\Actions\Action;
use Filament\Actions\BulkActionGroup; use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction; use Filament\Actions\DeleteBulkAction;
@ -36,7 +36,7 @@ class OrdersTable
TextColumn::make('count') TextColumn::make('count')
->numeric() ->numeric()
->sortable(), ->sortable(),
SelectColumn::make('orderstatus')->options(Orderstatus::class) TextColumn::make('orderstatus.name')
->searchable(), ->searchable(),
TextColumn::make('user.name') TextColumn::make('user.name')
->numeric() ->numeric()

View File

@ -6,11 +6,12 @@ use App\Observers\OrderObserver;
use Illuminate\Database\Eloquent\Attributes\ObservedBy; use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Models\Orderstatus;
#[ObservedBy([OrderObserver::class])] #[ObservedBy([OrderObserver::class])]
class Order extends Model class Order extends Model
{ {
protected $fillable = ["name", "url", "count", "orderstatus", "orderdatetime", "user_id"]; protected $fillable = ["name", "url", "count", "orderstatus_id", "orderdatetime", "user_id"];
public function user(): BelongsTo public function user(): BelongsTo
{ {

View File

@ -7,6 +7,7 @@ use App\Mail\OrderRegistered;
use App\Models\Order; use App\Models\Order;
use App\Models\User; use App\Models\User;
use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Mail;
use App\Models\Orderstatus;
class OrderObserver class OrderObserver
{ {
@ -24,9 +25,9 @@ class OrderObserver
*/ */
public function updated(Order $order): void public function updated(Order $order): void
{ {
$orderstatusArrived = Orderstatus::find("name", "angekommen")->first(); $orderstatusArrived = Orderstatus::where("name", "angekommen")->first();
if($order->orderstatus == $orderstatusArrived->id) { if($order->orderstatus_id == $orderstatusArrived->id) {
$user = $order->usery; $user = User::find($order->user_id);
Mail::to($user)->send(new OrderArrived($order)); Mail::to($user)->send(new OrderArrived($order));
} }
} }

120
config/filament.php Normal file
View File

@ -0,0 +1,120 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Broadcasting
|--------------------------------------------------------------------------
|
| By uncommenting the Laravel Echo configuration, you may connect Filament
| to any Pusher-compatible websockets server.
|
| This will allow your users to receive real-time notifications.
|
*/
'broadcasting' => [
// 'echo' => [
// 'broadcaster' => 'pusher',
// 'key' => env('VITE_PUSHER_APP_KEY'),
// 'cluster' => env('VITE_PUSHER_APP_CLUSTER'),
// 'wsHost' => env('VITE_PUSHER_HOST'),
// 'wsPort' => env('VITE_PUSHER_PORT'),
// 'wssPort' => env('VITE_PUSHER_PORT'),
// 'authEndpoint' => '/broadcasting/auth',
// 'disableStats' => true,
// 'encrypted' => true,
// 'forceTLS' => true,
// ],
],
/*
|--------------------------------------------------------------------------
| Default Filesystem Disk
|--------------------------------------------------------------------------
|
| This is the storage disk Filament will use to store files. You may use
| any of the disks defined in the `config/filesystems.php`.
|
*/
'default_filesystem_disk' => env('FILESYSTEM_DISK', 'local'),
/*
|--------------------------------------------------------------------------
| Assets Path
|--------------------------------------------------------------------------
|
| This is the directory where Filament's assets will be published to. It
| is relative to the `public` directory of your Laravel application.
|
| After changing the path, you should run `php artisan filament:assets`.
|
*/
'assets_path' => null,
/*
|--------------------------------------------------------------------------
| Cache Path
|--------------------------------------------------------------------------
|
| This is the directory that Filament will use to store cache files that
| are used to optimize the registration of components.
|
| After changing the path, you should run `php artisan filament:cache-components`.
|
*/
'cache_path' => base_path('bootstrap/cache/filament'),
/*
|--------------------------------------------------------------------------
| Livewire Loading Delay
|--------------------------------------------------------------------------
|
| This sets the delay before loading indicators appear.
|
| Setting this to 'none' makes indicators appear immediately, which can be
| desirable for high-latency connections. Setting it to 'default' applies
| Livewire's standard 200ms delay.
|
*/
'livewire_loading_delay' => 'default',
/*
|--------------------------------------------------------------------------
| File Generation
|--------------------------------------------------------------------------
|
| Artisan commands that generate files can be configured here by setting
| configuration flags that will impact their location or content.
|
| Often, this is useful to preserve file generation behavior from a
| previous version of Filament, to ensure consistency between older and
| newer generated files. These flags are often documented in the upgrade
| guide for the version of Filament you are upgrading to.
|
*/
'file_generation' => [
'flags' => [],
],
/*
|--------------------------------------------------------------------------
| System Route Prefix
|--------------------------------------------------------------------------
|
| This is the prefix used for the system routes that Filament registers,
| such as the routes for downloading exports and failed import rows.
|
*/
'system_route_prefix' => 'filament',
];

View File

@ -1,7 +1,7 @@
<?php <?php
use App\Models\User; use App\Models\User;
use App\Orderstatus; use App\Models\Orderstatus;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
@ -13,14 +13,13 @@ return new class extends Migration
*/ */
public function up(): void public function up(): void
{ {
$orderstatusRegistered = Orderstatus::find("name", "erfasst")->first();
Schema::create('orders', function (Blueprint $table) { Schema::create('orders', function (Blueprint $table) {
$table->id(); $table->id();
$table->timestamps(); $table->timestamps();
$table->string("name"); $table->string("name");
$table->string("url")->nullable(); $table->string("url")->nullable();
$table->integer("count")->nullable(); $table->integer("count")->nullable();
$table->foreignidfor(Orderstatus::class)->default($orderstatusRegistered->id); $table->foreignidfor(Orderstatus::class)->default(1);
$table->datetime("orderdatetime")->nullable(); $table->datetime("orderdatetime")->nullable();
$table->foreignIdFor(User::class); $table->foreignIdFor(User::class);
}); });