generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
613cf93
commit 0b9e295
Showing
10 changed files
with
519 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
namespace Jeffgreco13\FilamentWave\Filament\Resources; | ||
|
||
use Filament\Forms; | ||
use Filament\Tables; | ||
use Filament\Forms\Form; | ||
use Filament\Tables\Table; | ||
use Filament\Resources\Resource; | ||
use Filament\Support\Enums\FontWeight; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Database\Eloquent\SoftDeletingScope; | ||
use Jeffgreco13\FilamentWave\Filament\Resources\CustomerResource\Pages; | ||
use Jeffgreco13\FilamentWave\Filament\Resources\CustomerResource\RelationManagers; | ||
|
||
class CustomerResource extends Resource | ||
{ | ||
protected static ?string $navigationIcon = 'heroicon-o-identification'; | ||
|
||
public static string $modalWidth = "lg"; | ||
|
||
public static function getModel(): string | ||
{ | ||
return filament('wave')->getCustomerModel(); | ||
} | ||
|
||
public static function form(Form $form): Form | ||
{ | ||
return $form | ||
->columns(1) | ||
->schema([ | ||
Forms\Components\TextInput::make('name') | ||
->label('Customer or Business Name') | ||
->placeholder('Dunder Mifflin') | ||
->default('AAA Test') | ||
->required(), | ||
Forms\Components\Fieldset::make('Primary contact') | ||
->columns(2) | ||
->schema([ | ||
Forms\Components\TextInput::make('first_name') | ||
->default('Mike') | ||
->placeholder('Michael'), | ||
Forms\Components\TextInput::make('last_name') | ||
->default('Jones') | ||
->placeholder('Scott'), | ||
Forms\Components\TextInput::make('email') | ||
->default('mike.jones@gmail.com') | ||
->placeholder('mscott@dundermifflin.com') | ||
->email(), | ||
Forms\Components\TextInput::make('phone') | ||
->default('705-255-1775'), | ||
]), | ||
]); | ||
} | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
Tables\Columns\TextColumn::make('name') | ||
->searchable(['name', 'first_name', 'last_name']) | ||
->weight(FontWeight::Bold) | ||
->sortable() | ||
->description(fn ($record) => $record->name != $record->full_name ? $record->full_name : null), | ||
Tables\Columns\TextColumn::make('email') | ||
->searchable(), | ||
Tables\Columns\TextColumn::make('phone') | ||
->searchable() | ||
]) | ||
->filters([ | ||
// | ||
]) | ||
->actions([ | ||
Tables\Actions\EditAction::make()->modalWidth(self::$modalWidth), | ||
Tables\Actions\ActionGroup::make([ | ||
Tables\Actions\Action::make('archive') | ||
->label(fn ($record) => $record->is_archived ? 'Restore' : 'Archive') | ||
->color('warning') | ||
->icon('heroicon-s-archive-box') | ||
->action(function ($record) { | ||
$record->toggleArchive(); | ||
}), | ||
Tables\Actions\DeleteAction::make(), | ||
]), | ||
]) | ||
->bulkActions([ | ||
Tables\Actions\BulkActionGroup::make([ | ||
Tables\Actions\DeleteBulkAction::make(), | ||
]), | ||
]); | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ManageCustomers::route('/'), | ||
]; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/Filament/Resources/CustomerResource/Pages/ManageCustomers.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Jeffgreco13\FilamentWave\Filament\Resources\CustomerResource\Pages; | ||
|
||
use Filament\Actions; | ||
use Filament\Resources\Components\Tab; | ||
use Filament\Notifications\Notification; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Filament\Resources\Pages\ManageRecords; | ||
use Jeffgreco13\FilamentWave\Jobs\PullWaveCustomers; | ||
|
||
class ManageCustomers extends ManageRecords | ||
{ | ||
public static function getResource(): string | ||
{ | ||
return filament('wave')->getCustomerResource(); | ||
} | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\CreateAction::make()->modalWidth(self::getResource()::$modalWidth), | ||
Actions\ActionGroup::make([ | ||
Actions\Action::make('pull') | ||
->label('Pull from Wave') | ||
->icon('heroicon-o-arrow-down-circle') | ||
->requiresConfirmation() | ||
->modalDescription("This will pull all customers immediately. Do you want to continue?") | ||
->action(function(){ | ||
PullWaveCustomers::dispatchSync(); | ||
Notification::make()->success()->title('Customers pulled successfully.')->send(); | ||
}) | ||
]) | ||
]; | ||
} | ||
|
||
public function getTabs(): array | ||
{ | ||
return [ | ||
'active' => Tab::make() | ||
->modifyQueryUsing(fn (Builder $query) => $query->active()), | ||
'archived' => Tab::make() | ||
->modifyQueryUsing(fn (Builder $query) => $query->archived()), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Jeffgreco13\FilamentWave\Jobs; | ||
|
||
use Jeffgreco13\Wave\Wave; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Jeffgreco13\FilamentWave\Models\Customer; | ||
use Illuminate\Contracts\Queue\ShouldBeUnique; | ||
|
||
class PullWaveCustomers implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
/** | ||
* Create a new job instance. | ||
*/ | ||
public function __construct() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Execute the job. | ||
*/ | ||
public function handle(): void | ||
{ | ||
$wave = new Wave(); | ||
$response = $wave->customers(['pageSize'=>20]); | ||
do { | ||
foreach ($wave->getNodes() as $node) { | ||
$customer = Customer::firstOrNew(['id'=>$node->id]); | ||
$customer->fill([ | ||
'name' => $node->name, | ||
'email' => $node->email, | ||
'first_name' => $node->firstName, | ||
'last_name' => $node->lastName, | ||
'phone' => $node->phone | ||
]); | ||
$customer->saveQuietly(); | ||
} | ||
} while($response = $wave->paginate()); | ||
|
||
} | ||
} |
Oops, something went wrong.