Skip to content

Commit

Permalink
Fixed the issue of not showing menubar in the dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
alimranahmed committed Sep 10, 2024
1 parent 41964b6 commit efb92ea
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 87 deletions.
9 changes: 1 addition & 8 deletions app/Http/Controllers/Backend/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@
namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;
use App\Models\Category;
use App\Models\Comment;
use App\Models\Feedback;
use Illuminate\Contracts\View\View;

class DashboardController extends Controller
{
public function index(): View
{
$categories = Category::query()->withCount('articles')->get()->sortByDesc('articles_count');
$latestComments = Comment::query()->with('user')->latest()->take(3)->get();
$latestFeedbacks = Feedback::query()->where('is_closed', 0)->take(3)->get();

return view('backend.dashboard', compact('categories', 'latestComments', 'latestFeedbacks'));
return view('backend.dashboard');
}
}
24 changes: 24 additions & 0 deletions app/Livewire/Backend/Dashboard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Livewire\Backend;

use App\Models\Category;
use App\Models\Comment;
use App\Models\Feedback;
use Illuminate\Contracts\View\View;
use Livewire\Component;

class Dashboard extends Component
{
public function render(): View
{
$categories = Category::query()->withCount('articles')->get()->sortByDesc('articles_count');
$latestComments = Comment::query()->with('user')->latest()->take(3)->get();
$latestFeedbacks = Feedback::query()->where('is_closed', 0)->take(3)->get();

return view(
'livewire.backend.dashboard',
compact('categories', 'latestComments', 'latestFeedbacks')
);
}
}
72 changes: 1 addition & 71 deletions resources/views/backend/dashboard.blade.php
Original file line number Diff line number Diff line change
@@ -1,73 +1,3 @@
<x-backend>
<div class="flex flex-row">
<div class="basis-1/3">
<x-backend.table>
<x-slot name="head">
<tr>
<x-backend.table.th class="text-center">Latest Comments</x-backend.table.th>
</tr>
</x-slot>

<x-slot name="body">
@forelse($latestComments as $comment)
<tr>
<x-backend.table.td class="text-gray-600">
<span class="font-medium">{{$comment->user->name}}</span><br>
<span class="text-slate-400">{{$comment->createdAtHumanDiff}}</span><br>
{{$comment->content}}
</x-backend.table.td>
</tr>
@empty
@endforelse
</x-slot>
</x-backend.table>
</div>
<div class="basis-1/3">
<x-backend.table>
<x-slot name="head">
<tr>
<x-backend.table.th class="text-center">Latest Feedback</x-backend.table.th>
</tr>
</x-slot>

<x-slot name="body">
@forelse($latestFeedbacks as $feedback)
<tr>
<x-backend.table.td class="text-gray-600">
<span class="font-medium">{{$feedback->name}}</span><br>
<span class="text-slate-400">{{$feedback->createdAtHumanDiff}}</span><br>
{{$feedback->content}}
</x-backend.table.td>
</tr>
@empty
<x-backend.table.td colspan="100" class="text-gray-400 text-center">No new feedback</x-backend.table.td>
@endforelse
</x-slot>
</x-backend.table>
</div>
<div class="basis-1/3">
<x-backend.table>
<x-slot name="head">
<tr>
<x-backend.table.th class="text-center" colspan="100">Articles Categories</x-backend.table.th>
</tr>
</x-slot>

<x-slot name="body">
@forelse($categories as $category)
<tr>
<x-backend.table.td class="text-gray-600">
<span class="font-medium">{{$category->name}}</span>
</x-backend.table.td>
<x-backend.table.td class="text-gray-600">
<span class="text-slate-400">{{$category->articles_count}}</span><br>
</x-backend.table.td>
</tr>
@empty
<x-backend.table.td colspan="100" class="text-gray-400 text-center">No new feedback</x-backend.table.td>
@endforelse
</x-slot>
</x-backend.table>
</div>
</div>
<livewire:backend.dashboard/>
</x-backend>
71 changes: 71 additions & 0 deletions resources/views/livewire/backend/dashboard.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<div class="flex flex-row">
<div class="basis-1/3">
<x-backend.table>
<x-slot name="head">
<tr>
<x-backend.table.th class="text-center">Latest Comments</x-backend.table.th>
</tr>
</x-slot>

<x-slot name="body">
@forelse($latestComments as $comment)
<tr>
<x-backend.table.td class="text-gray-600">
<span class="font-medium">{{$comment->user->name}}</span><br>
<span class="text-slate-400">{{$comment->createdAtHumanDiff}}</span><br>
{{$comment->content}}
</x-backend.table.td>
</tr>
@empty
@endforelse
</x-slot>
</x-backend.table>
</div>
<div class="basis-1/3">
<x-backend.table>
<x-slot name="head">
<tr>
<x-backend.table.th class="text-center">Latest Feedback</x-backend.table.th>
</tr>
</x-slot>

<x-slot name="body">
@forelse($latestFeedbacks as $feedback)
<tr>
<x-backend.table.td class="text-gray-600">
<span class="font-medium">{{$feedback->name}}</span><br>
<span class="text-slate-400">{{$feedback->createdAtHumanDiff}}</span><br>
{{$feedback->content}}
</x-backend.table.td>
</tr>
@empty
<x-backend.table.td colspan="100" class="text-gray-400 text-center">No new feedback</x-backend.table.td>
@endforelse
</x-slot>
</x-backend.table>
</div>
<div class="basis-1/3">
<x-backend.table>
<x-slot name="head">
<tr>
<x-backend.table.th class="text-center" colspan="100">Articles Categories</x-backend.table.th>
</tr>
</x-slot>

<x-slot name="body">
@forelse($categories as $category)
<tr>
<x-backend.table.td class="text-gray-600">
<span class="font-medium">{{$category->name}}</span>
</x-backend.table.td>
<x-backend.table.td class="text-gray-600">
<span class="text-slate-400">{{$category->articles_count}}</span><br>
</x-backend.table.td>
</tr>
@empty
<x-backend.table.td colspan="100" class="text-gray-400 text-center">No new feedback</x-backend.table.td>
@endforelse
</x-slot>
</x-backend.table>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ public function testIndex()
{
$this->actingAs($this->user)->get('/admin/dashboard')
->assertStatus(Response::HTTP_OK)
->assertViewIs('backend.dashboard')
->assertViewHas('categories')
->assertViewHas('latestComments')
->assertViewHas('latestFeedbacks');
->assertViewIs('backend.dashboard');
}
}
5 changes: 1 addition & 4 deletions tests/Feature/Controllers/HomeControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ public function testAdminDashboard()

$this->actingAs($user)
->get('/')
->assertViewIs('backend.dashboard')
->assertViewHas('categories')
->assertViewHas('latestComments')
->assertViewHas('latestFeedbacks');
->assertViewIs('backend.dashboard');
}

public function testGetMessage()
Expand Down
20 changes: 20 additions & 0 deletions tests/Feature/Livewire/Backend/DashboardTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Tests\Feature\Livewire\Backend;

use App\Livewire\Backend\Dashboard;
use Livewire\Livewire;
use Tests\TestCase;

class DashboardTest extends TestCase
{
public function testRender()
{
Livewire::test(Dashboard::class)
->assertOk()
->assertViewIs('livewire.backend.dashboard')
->assertViewHas('categories')
->assertViewHas('latestComments')
->assertViewHas('latestFeedbacks');
}
}

0 comments on commit efb92ea

Please sign in to comment.