Created
February 14, 2021 19:50
-
-
Save jongravois/4663a8604d78408482a1cc905c997a76 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
namespace App\Http\Livewire\Levo; | |
use App\Models\CompanyType; | |
use App\Models\ReportsSalesTeam; | |
use Livewire\Component; | |
class AdminTypes extends Component | |
{ | |
public $type; | |
public $showEditor = false; | |
protected $rules = [ | |
'type.title' => 'nullable', | |
]; | |
public function mount(): void | |
{ | |
$this->type = CompanyType::make(); | |
} // end function | |
public function render() | |
{ | |
return view('livewire.levo.admin-types', [ | |
'types' => CompanyType::orderBy('sort_order')->get() | |
]); | |
} // end function | |
public function createType(): void | |
{ | |
$this->type = CompanyType::make(); | |
$this->showEditor = true; | |
} // end function | |
public function deleteType($id): void | |
{ | |
CompanyType::find($id)->delete(); | |
$this->dispatchBrowserEvent('toast', [ | |
'type' => 'success', | |
'msg' => 'This has been deleted' | |
]); | |
} // end function | |
public function editType($id): void | |
{ | |
$this->type = CompanyType::whereId($id)->first(); | |
$this->showEditor = true; | |
} // end function | |
public function persistType(): void | |
{ | |
$this->type->save(); | |
$this->type = CompanyType::make(); | |
$this->showEditor = false; | |
} // end function | |
public function toggleTypesVisible($id): void | |
{ | |
$type = CompanyType::whereId($id)->first(); | |
$type->report_visible = !$type->report_visible; | |
$type->save(); | |
} // end function | |
public function updateOrder($groupsStructure): void | |
{ | |
foreach($groupsStructure as $groupitem) { | |
CompanyType::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