Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger searchable when records are updated. #1699

Merged
merged 6 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/admin/src/Events/ChildCollectionCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Lunar\Admin\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ChildCollectionCreated
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(
public Model $model
) {
}
}
21 changes: 21 additions & 0 deletions packages/admin/src/Events/CollectionProductAttached.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Lunar\Admin\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class CollectionProductAttached
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(
public Model $model
) {
}
}
21 changes: 21 additions & 0 deletions packages/admin/src/Events/CollectionProductDetached.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Lunar\Admin\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class CollectionProductDetached
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(
public Model $model
) {
}
}
21 changes: 21 additions & 0 deletions packages/admin/src/Events/CustomerAddressEdited.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Lunar\Admin\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class CustomerAddressEdited
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(
public Model $model
) {
}
}
21 changes: 21 additions & 0 deletions packages/admin/src/Events/CustomerUserEdited.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Lunar\Admin\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class CustomerUserEdited
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(
public Model $model
) {
}
}
21 changes: 21 additions & 0 deletions packages/admin/src/Events/ModelChannelsUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Lunar\Admin\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ModelChannelsUpdated
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(
public Model $model
) {
}
}
21 changes: 21 additions & 0 deletions packages/admin/src/Events/ModelMediaUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Lunar\Admin\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ModelMediaUpdated
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(
public Model $model
) {
}
}
21 changes: 21 additions & 0 deletions packages/admin/src/Events/ModelPricesUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Lunar\Admin\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ModelPricesUpdated
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(
public Model $model
) {
}
}
21 changes: 21 additions & 0 deletions packages/admin/src/Events/ModelUrlsUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Lunar\Admin\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ModelUrlsUpdated
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(
public Model $model
) {
}
}
21 changes: 21 additions & 0 deletions packages/admin/src/Events/ProductAssociationsUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Lunar\Admin\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ProductAssociationsUpdated
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(
public Model $model
) {
}
}
21 changes: 21 additions & 0 deletions packages/admin/src/Events/ProductCollectionsUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Lunar\Admin\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ProductCollectionsUpdated
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(
public Model $model
) {
}
}
21 changes: 21 additions & 0 deletions packages/admin/src/Events/ProductCustomerGroupsUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Lunar\Admin\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ProductCustomerGroupsUpdated
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(
public Model $model
) {
}
}
21 changes: 21 additions & 0 deletions packages/admin/src/Events/ProductPricingUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Lunar\Admin\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ProductPricingUpdated
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(
public Model $model
) {
}
}
21 changes: 21 additions & 0 deletions packages/admin/src/Events/ProductVariantOptionsUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Lunar\Admin\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ProductVariantOptionsUpdated
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(
public Model $model
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Filament\Tables\Table;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Database\Eloquent\Model;
use Lunar\Admin\Events\ChildCollectionCreated;
use Lunar\Admin\Filament\Resources\CollectionResource;
use Lunar\Admin\Support\Pages\BaseManageRelatedRecords;
use Lunar\Admin\Support\Tables\Actions\Collections\CreateChildCollection;
Expand Down Expand Up @@ -73,7 +74,9 @@ public function table(Table $table): Table
return CollectionResource::getUrl('edit', ['record' => $record]);
}),
])->headerActions([
CreateChildCollection::make('createChildCollection'),
CreateChildCollection::make('createChildCollection')->after(
fn () => ChildCollectionCreated::dispatch($this->getRecord())
),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Relation;
use Lunar\Admin\Events\CollectionProductAttached;
use Lunar\Admin\Events\CollectionProductDetached;
use Lunar\Admin\Filament\Resources\CollectionResource;
use Lunar\Admin\Filament\Resources\ProductResource;
use Lunar\Admin\Support\Pages\BaseManageRelatedRecords;
Expand Down Expand Up @@ -67,7 +69,9 @@ public function table(Table $table): Table
->formatStateUsing(fn (Model $record): string => $record->translateAttribute('name'))
->label(__('lunarpanel::product.table.name.label')),
])->actions([
Tables\Actions\DetachAction::make(),
Tables\Actions\DetachAction::make()->after(
fn () => CollectionProductDetached::dispatch($this->getOwnerRecord())
),
Tables\Actions\EditAction::make()->url(
fn (Model $record) => ProductResource::getUrl('edit', [
'record' => $record,
Expand Down Expand Up @@ -96,6 +100,10 @@ public function table(Table $table): Table
$relationship->attach($product, [
'position' => $relationship->count() + 1,
]);

CollectionProductAttached::dispatch($this->getOwnerRecord());

$product->searchable();
}),
])->reorderable('position');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Lunar\Admin\Events\CustomerAddressEdited;
use Lunar\Models\Address;
use Lunar\Models\State;

Expand Down Expand Up @@ -67,6 +68,9 @@ public function table(Table $table): Table
),
])->actions([
Tables\Actions\EditAction::make('editAddress')
->after(
fn (Model $record) => CustomerAddressEdited::dispatch($record)
)
->fillForm(fn (Address $record): array => [
'title' => $record->title,
'first_name' => $record->first_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Hash;
use Lunar\Admin\Events\CustomerUserEdited;

class UserRelationManager extends RelationManager
{
Expand All @@ -27,6 +29,9 @@ public function table(Table $table): Table
->label(__('lunarpanel::user.table.email.label')),
])->actions([
Tables\Actions\EditAction::make('edit')
->after(
fn (Model $record) => CustomerUserEdited::dispatch($record)
)
->form([
Group::make([
TextInput::make('email')
Expand Down
Loading
Loading