-
app/Models/Comment.php
Open in GitHubuse Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; class Comment extends Model { public function scopeLastWeek(Builder $query): Builder { return $query->whereBetween('posted_at', [carbon('1 week ago'), now()]) ->latest(); } }
-
app/Http/Controllers/Admin/ShowDashboard.php
Open in GitHubuse App\Http\Controllers\Controller; use App\Models\Comment; use App\Models\Post; use App\Models\User; class ShowDashboard extends Controller { public function __invoke(): View { return view('admin.dashboard.index', [ 'comments' => Comment::lastWeek()->get(), 'posts' => Post::lastWeek()->get(), 'users' => User::lastWeek()->get(), ]); } }