-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
1,136 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Tags; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\Tag; | ||
use Illuminate\Http\Request; | ||
use Illuminate\View\View; | ||
|
||
class EditController extends Controller | ||
{ | ||
public function __invoke(Request $request, Tag $tag): View | ||
{ | ||
return view('tags.edit', [ | ||
'tag' => $tag, | ||
]); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Tags; | ||
|
||
use App\Models\Tag; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Redirect; | ||
use Illuminate\View\View; | ||
use Livewire\Component; | ||
use Livewire\Features\SupportRedirects\Redirector; | ||
use Masmerise\Toaster\Toaster; | ||
|
||
class CreateForm extends Component | ||
{ | ||
public string $label; | ||
public ?string $description; | ||
|
||
public function submit(): RedirectResponse|Redirector | ||
{ | ||
$this->validate([ | ||
'label' => ['required', 'string'], | ||
'description' => ['nullable', 'string'], | ||
], [ | ||
'label.required' => __('Please enter a label.'), | ||
]); | ||
|
||
$tag = Tag::create([ | ||
'user_id' => Auth::id(), | ||
'label' => $this->label, | ||
'description' => $this->description ?? null, | ||
]); | ||
|
||
Toaster::success(__('The tag :label has been added.', ['label' => $tag->label])); | ||
|
||
return Redirect::route('tags.index'); | ||
} | ||
|
||
public function render(): View | ||
{ | ||
return view('livewire.tags.create-form'); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Tags; | ||
|
||
use App\Models\Tag; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Support\Facades\Redirect; | ||
use Illuminate\View\View; | ||
use Livewire\Component; | ||
use Livewire\Features\SupportRedirects\Redirector; | ||
use Masmerise\Toaster\Toaster; | ||
|
||
class DeleteTagButton extends Component | ||
{ | ||
public Tag $tag; | ||
|
||
public function mount(Tag $tag): void | ||
{ | ||
$this->tag = $tag; | ||
} | ||
|
||
public function delete(): RedirectResponse|Redirector | ||
{ | ||
$this->authorize('forceDelete', $this->tag); | ||
|
||
Toaster::success("The tag {$this->tag->label} has been removed."); | ||
|
||
$this->tag->forceDelete(); | ||
|
||
return Redirect::route('tags.index'); | ||
} | ||
|
||
public function render(): View | ||
{ | ||
return view('livewire.tags.delete-tag-button'); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Tags; | ||
|
||
use App\Models\Tag; | ||
use Illuminate\View\View; | ||
use Livewire\Component; | ||
|
||
class IndexItem extends Component | ||
{ | ||
public Tag $tag; | ||
|
||
public function mount(Tag $tag): void | ||
{ | ||
$this->tag = $tag; | ||
} | ||
|
||
public function render(): View | ||
{ | ||
return view('livewire.tags.index-item'); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Tags; | ||
|
||
use App\Models\Tag; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\View\View; | ||
use Livewire\Component; | ||
use Livewire\WithPagination; | ||
|
||
class IndexTable extends Component | ||
{ | ||
use withPagination; | ||
|
||
public function render(): View | ||
{ | ||
$tags = Tag::where('user_id', Auth::id()) | ||
->orderBy('created_at', 'desc') | ||
->paginate(30, pageName: 'tags'); | ||
|
||
return view('livewire.tags.index-table', ['tags' => $tags]); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace App\Livewire\Tags; | ||
|
||
use App\Models\Tag; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Support\Facades\Redirect; | ||
use Illuminate\View\View; | ||
use Livewire\Component; | ||
use Livewire\Features\SupportRedirects\Redirector; | ||
use Masmerise\Toaster\Toaster; | ||
|
||
class UpdateForm extends Component | ||
{ | ||
public string $label; | ||
public ?string $description; | ||
|
||
public Tag $tag; | ||
|
||
public function mount(Tag $tag): void | ||
{ | ||
$this->tag = $tag; | ||
$this->label = $tag->label; | ||
$this->description = $tag->description ?? null; | ||
} | ||
|
||
public function submit(): RedirectResponse|Redirector | ||
{ | ||
$this->authorize('update', $this->tag); | ||
|
||
$this->validate([ | ||
'label' => ['required', 'string'], | ||
'description' => ['nullable', 'string'], | ||
], [ | ||
'label.required' => __('Please enter a label.'), | ||
]); | ||
|
||
$this->tag->update([ | ||
'label' => $this->label, | ||
'description' => $this->description ?? null, | ||
]); | ||
|
||
$this->tag->save(); | ||
|
||
Toaster::success(__('The tag :label has been updated.', ['label' => $this->tag->label])); | ||
|
||
return Redirect::route('tags.index'); | ||
} | ||
|
||
public function render(): View | ||
{ | ||
return view('livewire.tags.update-form'); | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
|
||
class Tag extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $guarded = []; | ||
|
||
public function user(): BelongsTo | ||
{ | ||
return $this->belongsTo(User::class); | ||
} | ||
} |
Oops, something went wrong.