mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
initial commit
This commit is contained in:
parent
32d63c09e7
commit
01655b413e
37 changed files with 2564 additions and 283 deletions
59
app/Livewire/DeviceManager.php
Normal file
59
app/Livewire/DeviceManager.php
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\Device;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
class DeviceManager extends Component
|
||||
{
|
||||
use WithPagination;
|
||||
|
||||
public $showDeviceForm = false;
|
||||
|
||||
public $name;
|
||||
|
||||
public $mac_address;
|
||||
|
||||
public $api_key;
|
||||
|
||||
public $default_refresh_interval = 900;
|
||||
|
||||
public $friendly_id;
|
||||
|
||||
protected $rules = [
|
||||
'mac_address' => 'required',
|
||||
'api_key' => 'required',
|
||||
'default_refresh_interval' => 'required|integer',
|
||||
];
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.device-manager', [
|
||||
'devices' => auth()->user()->devices()->paginate(10),
|
||||
]);
|
||||
}
|
||||
|
||||
public function createDevice(): void
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
Device::factory([
|
||||
'name' => $this->name,
|
||||
'mac_address' => $this->mac_address,
|
||||
'api_key' => $this->api_key,
|
||||
'default_refresh_interval' => $this->default_refresh_interval,
|
||||
'friendly_id' => $this->friendly_id,
|
||||
'user_id' => auth()->id(),
|
||||
])->create();
|
||||
|
||||
$this->reset();
|
||||
session()->flash('message', 'Device created successfully.');
|
||||
}
|
||||
|
||||
public function toggleDeviceForm()
|
||||
{
|
||||
$this->showDeviceForm = ! $this->showDeviceForm;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue