Skip to content

Commit

Permalink
#187: All unncessary backend controllers replaced by full page component
Browse files Browse the repository at this point in the history
  • Loading branch information
alimranahmed committed Sep 12, 2024
1 parent a2ed6cd commit f2b885f
Show file tree
Hide file tree
Showing 61 changed files with 478 additions and 668 deletions.
7 changes: 7 additions & 0 deletions app/Http/Controllers/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@

class ArticleController extends Controller
{
public function index(Request $request): View
{
$articles = Article::getPaginated($request);

return view('frontend.articles.index', compact('articles'));
}

public function show(string $slug): mixed
{
$article = Article::query()
Expand Down
34 changes: 0 additions & 34 deletions app/Http/Controllers/Backend/ArticleController.php

This file was deleted.

14 changes: 0 additions & 14 deletions app/Http/Controllers/Backend/CategoryController.php

This file was deleted.

25 changes: 0 additions & 25 deletions app/Http/Controllers/Backend/CommentController.php

This file was deleted.

14 changes: 0 additions & 14 deletions app/Http/Controllers/Backend/ConfigController.php

This file was deleted.

14 changes: 0 additions & 14 deletions app/Http/Controllers/Backend/DashboardController.php

This file was deleted.

14 changes: 0 additions & 14 deletions app/Http/Controllers/Backend/FeedbackController.php

This file was deleted.

17 changes: 0 additions & 17 deletions app/Http/Controllers/Backend/KeywordController.php

This file was deleted.

13 changes: 0 additions & 13 deletions app/Http/Controllers/Backend/SubscriberController.php

This file was deleted.

8 changes: 3 additions & 5 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@

namespace App\Http\Controllers;

use App\Http\Controllers\Backend\DashboardController;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class HomeController extends Controller
{
public function index(Request $request): View
public function index(Request $request): RedirectResponse|View
{
if (Auth::check()) {
$dashboard = new DashboardController();

return $dashboard->index();
return redirect()->route('admin-dashboard');
} else {
return (new ArticleController())->index($request);
}
Expand Down
40 changes: 0 additions & 40 deletions app/Http/Controllers/UserController.php

This file was deleted.

7 changes: 7 additions & 0 deletions app/Livewire/Backend/Article/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ class Form extends Component
public function mount($article = null): void
{
if ($article?->id) {
/** @var User $user */
$user = Auth::user();
if (! $article->hasAuthorization($user)) {
$this->redirectRoute('home');
return;
}

$this->originalArticle = $article;
$this->articleData = $article->toArray();
$this->articleData['keywords'] = $article->keywords->pluck('name')->implode(' ');
Expand Down
1 change: 1 addition & 0 deletions app/Livewire/Backend/Category/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Arr;
use Livewire\Attributes\Lazy;
use Livewire\Component;

class Index extends Component
Expand Down
38 changes: 21 additions & 17 deletions app/Livewire/Backend/Comment/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,44 @@
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Routing\Redirector;
use Illuminate\Support\Arr;
use Livewire\Component;

class Edit extends Component
{
public array $rules = [
'comment.content' => 'string|required',
'comment.is_published' => 'boolean',
'content' => 'string|required',
'is_published' => 'boolean',
];

public ?Comment $comment;
public Comment $comment;

public ?string $content;
public ?bool $is_published = false;

public function mount(Comment $comment): void
{
$this->comment = $comment;
$this->content = $comment->content;
$this->is_published = (bool)$this->is_published;
}

public function render(): View
{
return view('livewire.backend.comment.edit');
}

public function update(Comment $comment): RedirectResponse|Redirector
public function update(): RedirectResponse|Redirector
{
$data = $this->validate();
$this->validate();

$comment->update([
'is_published' => $isPublished = Arr::get($data, 'comment.is_published', false),
$this->comment->update([
'is_published' => $isPublished = $this->is_published,
'published_at' => $isPublished ? now() : null,
'content' => Arr::get($data, 'comment.content', $comment->content),
'original_content' => $comment->count_edit ? $comment->original_content : $comment->content,
'count_edit' => $comment->count_edit + 1,
'content' => $this->content,
'original_content' => $this->comment->count_edit ? $this->comment->original_content : $this->comment->content,
'count_edit' => $this->comment->count_edit + 1,
]);

return redirect()->to(route('backend.comment.show', $comment->parent_comment_id ?? $comment->id));
return redirect()->to(route('backend.comment.show', $comment->parent_comment_id ?? $this->comment->id));
}

public function render(): View
{
return view('livewire.backend.comment.edit');
}
}
2 changes: 2 additions & 0 deletions app/Livewire/Backend/Comment/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
use Illuminate\Contracts\View\View;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\Lazy;
use Livewire\Attributes\Url;
use Livewire\Component;
use Livewire\WithPagination;

#[Lazy]
class Index extends Component
{
use WithPagination;
Expand Down
2 changes: 2 additions & 0 deletions app/Livewire/Backend/Feedback/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

use App\Models\Feedback;
use Illuminate\Contracts\View\View;
use Livewire\Attributes\Lazy;
use Livewire\Component;
use Livewire\WithPagination;

#[Lazy]
class Index extends Component
{
use WithPagination;
Expand Down
2 changes: 2 additions & 0 deletions app/Livewire/Backend/Subscriber/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

use App\Models\Subscriber;
use Illuminate\Contracts\View\View;
use Livewire\Attributes\Lazy;
use Livewire\Component;

#[Lazy]
class Index extends Component
{
public function placeholder(): View
Expand Down
2 changes: 2 additions & 0 deletions app/Livewire/Backend/User/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

use App\Models\User;
use Illuminate\Contracts\View\View;
use Livewire\Attributes\Lazy;
use Livewire\Component;
use Livewire\WithPagination;
use Symfony\Component\HttpFoundation\Response;

#[Lazy]
class Index extends Component
{
use WithPagination;
Expand Down
17 changes: 17 additions & 0 deletions app/Livewire/Backend/User/Profile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Livewire\Backend\User;

use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;

class Profile extends Component
{
public function render(): View
{
$user = Auth::user();

return view('livewire.backend.user.profile', compact('user'));
}
}
2 changes: 1 addition & 1 deletion app/Models/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Tempest\Highlight\Highlighter;

/**
* @property string $category
* @property Category $category
* @property int $user_id
* @property string $content
* @property array $meta
Expand Down
Loading

0 comments on commit f2b885f

Please sign in to comment.