update
This commit is contained in:
parent
ed1c1df4f0
commit
f52c59317d
13 changed files with 155 additions and 49 deletions
|
@ -23,7 +23,6 @@ class Version extends Page
|
|||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
|
||||
public $currentVersionOfApp = 0;
|
||||
public $latestVersionOfApp = 0;
|
||||
public $latestDownloadDateOfApp = 0;
|
||||
|
|
37
web/app/Events/ModelHostingSubscriptionCreated.php
Normal file
37
web/app/Events/ModelHostingSubscriptionCreated.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class ModelHostingSubscriptionCreated
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $model;
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct($model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [
|
||||
new PrivateChannel('channel-name'),
|
||||
];
|
||||
}
|
||||
}
|
37
web/app/Events/ModelHostingSubscriptionDeleting.php
Normal file
37
web/app/Events/ModelHostingSubscriptionDeleting.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class ModelHostingSubscriptionDeleting
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $model;
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct($model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [
|
||||
new PrivateChannel('channel-name'),
|
||||
];
|
||||
}
|
||||
}
|
|
@ -31,15 +31,17 @@ class CustomerResource extends Resource
|
|||
|
||||
Forms\Components\TextInput::make('name')
|
||||
->prefixIcon('heroicon-s-user')
|
||||
->required(),
|
||||
->required()->columnSpanFull(),
|
||||
Forms\Components\TextInput::make('username')
|
||||
->helperText('Username will be generated automatically based on the customer name')
|
||||
->prefixIcon('heroicon-s-user')
|
||||
->disabled(),
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('password')
|
||||
->password()
|
||||
->prefixIcon('heroicon-s-lock-closed')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('email')
|
||||
->prefixIcon('heroicon-s-envelope')
|
||||
->email()
|
||||
->unique('customers', 'email')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('phone'),
|
||||
Forms\Components\TextInput::make('address'),
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace app\Filament\Widgets;
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use Leandrocfe\FilamentApexCharts\Widgets\ApexChartWidget;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace app\Http\Controllers\Api;
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Api\Request\CustomerCreateRequest;
|
||||
use App\Http\Controllers\ApiController;
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\ModelHostingSubscriptionCreated;
|
||||
|
||||
class ModelHostingSubscriptionCreatedListener
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*/
|
||||
public function handle(ModelHostingSubscriptionCreated $event): void
|
||||
{
|
||||
|
||||
dd($event);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace app\Listeners;
|
||||
|
||||
use App\Events\ModelHostingSubscriptionCreated;
|
||||
use App\Events\ModelHostingSubscriptionDeleting;
|
||||
|
||||
class ModelHostingSubscriptionDeletingListener
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*/
|
||||
public function handle(ModelHostingSubscriptionDeleting $event): void
|
||||
{
|
||||
|
||||
dd($event);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -2,12 +2,9 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Events\ModelCustomerCreated;
|
||||
use App\Events\ModelCustomerDeleting;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
|
||||
class Customer extends Model
|
||||
{
|
||||
|
@ -15,6 +12,8 @@ class Customer extends Model
|
|||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'username',
|
||||
'password',
|
||||
'email',
|
||||
'phone',
|
||||
'address',
|
||||
|
@ -25,28 +24,9 @@ class Customer extends Model
|
|||
'company',
|
||||
];
|
||||
|
||||
public static function boot()
|
||||
public function hostingSubscriptions()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::created(function ($model) {
|
||||
event(new ModelCustomerCreated($model));
|
||||
});
|
||||
|
||||
static::deleting(function ($model) {
|
||||
$findWebsites = Website::where('customer_id', $model->id)->count();
|
||||
if ($findWebsites > 0) {
|
||||
throw new \ErrorException('Customer has websites, please delete them first.');
|
||||
return false;
|
||||
}
|
||||
event(new ModelCustomerDeleting($model));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public function websites()
|
||||
{
|
||||
return $this->hasMany(Website::class);
|
||||
return $this->hasMany(HostingSubscription::class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,20 +26,11 @@ class HostingSubscription extends Model
|
|||
parent::boot();
|
||||
|
||||
static::created(function ($model) {
|
||||
|
||||
$createWebsite = new Website();
|
||||
$createWebsite->domain = $model->domain;
|
||||
$createWebsite->customer_id = $model->customer_id;
|
||||
$createWebsite->hosting_plan_id = $model->hosting_plan_id;
|
||||
$createWebsite->save();
|
||||
|
||||
event(new \App\Events\ModelHostingSubscriptionCreated($model));
|
||||
});
|
||||
|
||||
static::deleting(function ($model) {
|
||||
$findWebsite = Website::where('domain', $model->domain)->first();
|
||||
if ($findWebsite) {
|
||||
$findWebsite->delete();
|
||||
}
|
||||
event(new \App\Events\ModelHostingSubscriptionDeleting($model));
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
@ -2,14 +2,18 @@
|
|||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Events\ModelCustomerCreated;
|
||||
use App\Events\ModelCustomerDeleting;
|
||||
|
||||
use App\Events\ModelHostingSubscriptionCreated;
|
||||
use App\Events\ModelHostingSubscriptionDeleting;
|
||||
|
||||
use App\Listeners\ModelHostingSubscriptionCreatedListener;
|
||||
use App\Listeners\ModelHostingSubscriptionDeletingListener;
|
||||
|
||||
use App\Events\ModelWebsiteCreated;
|
||||
use App\Events\ModelWebsiteDeleting;
|
||||
use App\Listeners\ModelCustomerCreatedListener;
|
||||
use App\Listeners\ModelCustomerDeletingListener;
|
||||
use App\Listeners\ModelWebsiteCreatedListener;
|
||||
use App\Listeners\ModelWebsiteDeletingListener;
|
||||
|
||||
use App\Policies\CustomerPolicy;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
@ -47,7 +51,8 @@ class AppServiceProvider extends ServiceProvider
|
|||
|
||||
Event::listen(ModelWebsiteCreated::class,ModelWebsiteCreatedListener::class);
|
||||
Event::listen(ModelWebsiteDeleting::class,ModelWebsiteDeletingListener::class);
|
||||
Event::listen(ModelCustomerCreated::class,ModelCustomerCreatedListener::class);
|
||||
Event::listen(ModelCustomerDeleting::class,ModelCustomerDeletingListener::class);
|
||||
|
||||
Event::listen(ModelHostingSubscriptionCreated::class,ModelHostingSubscriptionCreatedListener::class);
|
||||
Event::listen(ModelHostingSubscriptionDeleting::class,ModelHostingSubscriptionDeletingListener::class);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue