Skip to content

Instantly share code, notes, and snippets.

@jongravois
Created February 14, 2021 19:49
Show Gist options
  • Save jongravois/d0f5f9aaf9c53c48dbb4e94f6042c94a to your computer and use it in GitHub Desktop.
Save jongravois/d0f5f9aaf9c53c48dbb4e94f6042c94a to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Livewire\Levo;
use App\Models\CompanyType;
use App\Models\ReportsSalesTeam;
use Livewire\Component;
class AdminSales extends Component
{
public $sale;
public $showEditor = false;
protected $rules = [
'sale.title' => 'nullable',
'sale.salesperson_code' => 'nullable'
];
public function mount(): void
{
$this->sale = ReportsSalesTeam::make();
} // end function
public function render()
{
return view('livewire.levo.admin-sales', [
'sales' => ReportsSalesTeam::orderBy('sort_order')->get()
]);
} // end function
public function createSale(): void
{
$this->sale = ReportsSalesTeam::make();
$this->showEditor = true;
} // end function
public function deleteSale($id): void
{
ReportsSalesTeam::find($id)->delete();
$this->dispatchBrowserEvent('toast', [
'type' => 'success',
'msg' => 'This has been deleted'
]);
} // end function
public function editSale($id): void
{
$this->sale = ReportsSalesTeam::whereId($id)->first();
$this->showSalesEditor = true;
} // end function
public function persistSale(): void
{
$this->sale->save();
$this->sale = ReportsSalesTeam::make();
$this->showEditor = false;
} // end function
public function updateOrder($groupsStructure): void
{
foreach($groupsStructure as $groupitem) {
ReportsSalesTeam::whereId($groupitem['value'])->update([
'sort_order' => $groupitem['order']
]);
} // end foreach
} // end function
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment