Demo project
This commit is contained in:
1 parent
5e4f3540e8
commit
a68267d0f0
146 files changed
+41587
No files matched your search
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class Categories extends Component
|
||||
{
|
||||
public $name;
|
||||
public $deleteID;
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.categories', [
|
||||
'categories' => \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->get()
|
||||
]);
|
||||
}
|
||||
|
||||
public function create() {
|
||||
if(trim($this->name) == "") {
|
||||
$this->name = ""; return;
|
||||
}
|
||||
|
||||
$existing = \App\Models\Category::where("user_id", \Auth::user()->id)->where("name", $this->name)->first();
|
||||
if($existing != null) {
|
||||
$this->name = ""; return;
|
||||
}
|
||||
|
||||
$highest = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority", "desc")->first();
|
||||
if($highest != null) {
|
||||
$highest = $highest->priority;
|
||||
} else {
|
||||
$highest = 0;
|
||||
}
|
||||
|
||||
$cat = new \App\Models\Category();
|
||||
$cat->user_id = \Auth::user()->id;
|
||||
$cat->name = trim($this->name);
|
||||
$cat->priority = $highest + 1;
|
||||
$cat->save();
|
||||
|
||||
$this->name = "";
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$cat = \App\Models\Category::where("user_id", \Auth::user()->id)->where("id", $this->deleteID)->first();
|
||||
if($cat) {
|
||||
$cat->delete();
|
||||
}
|
||||
}
|
||||
|
||||
public function moveUp($catID) {
|
||||
$cat = \App\Models\Category::where("user_id", \Auth::user()->id)->where("id", $catID)->first();
|
||||
if($cat) {
|
||||
$cat->move(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function moveDown($catID) {
|
||||
$cat = \App\Models\Category::where("user_id", \Auth::user()->id)->where("id", $catID)->first();
|
||||
if($cat) {
|
||||
$cat->move(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user