Add all files
This commit is contained in:
23
app/Livewire/Traits/Disabled.php
Normal file
23
app/Livewire/Traits/Disabled.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Traits;
|
||||
|
||||
trait Disabled
|
||||
{
|
||||
public function bootDisabled()
|
||||
{
|
||||
// Read class-level attributes
|
||||
$reflection = new \ReflectionClass($this);
|
||||
$attributes = $reflection->getAttributes(\App\Attributes\DisabledIf::class);
|
||||
|
||||
// Check if the DisabledIf attribute is present
|
||||
foreach ($attributes as $attribute) {
|
||||
$instance = $attribute->newInstance();
|
||||
// Check the condition based on the attribute's setting
|
||||
if (config('settings.' . $instance->setting, $instance->default)) {
|
||||
// If the condition is met, abort with a 404 error
|
||||
abort(404, 'This feature is currently disabled.');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
app/Livewire/Traits/HasNotifications.php
Normal file
27
app/Livewire/Traits/HasNotifications.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Traits;
|
||||
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
trait HasNotifications
|
||||
{
|
||||
public function bootHasNotifications()
|
||||
{
|
||||
if (Session::has('notification')) {
|
||||
$this->notify(
|
||||
Session::get('notification')['message'],
|
||||
Session::get('notification')['type']
|
||||
);
|
||||
Session::forget('notification');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifications
|
||||
*/
|
||||
public function notify($message, $type = 'success')
|
||||
{
|
||||
$this->dispatch('notify', ['message' => $message, 'type' => $type]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user