69 lines
1.8 KiB
PHP
69 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Airport;
|
|
use App\Models\Comment;
|
|
use App\Models\Favorite;
|
|
use App\Models\Flight;
|
|
use App\Models\Payment;
|
|
use App\Models\Tour;
|
|
use App\Models\User;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
use App\Exports\VisitsExport;
|
|
use App\Models\VisitStatistic;
|
|
use Illuminate\Support\Carbon;
|
|
use Hekmatinasser\Verta\Verta;
|
|
|
|
class DashboardController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$usersCount = User::count();
|
|
|
|
$toursCount = Tour::count();
|
|
|
|
$flightsCount = Flight::count();
|
|
|
|
$airportsCount = Airport::count();
|
|
|
|
$commentsCount = Comment::count();
|
|
|
|
$favoritesCount = Favorite::count();
|
|
|
|
$paymentsCount = Payment::count();
|
|
|
|
return view('admin.dashboard', compact(
|
|
'usersCount',
|
|
'toursCount',
|
|
'flightsCount',
|
|
'airportsCount',
|
|
'commentsCount',
|
|
'favoritesCount',
|
|
'paymentsCount'
|
|
));
|
|
}
|
|
|
|
public function exportExcel()
|
|
{
|
|
// ۱. لیست کاربران با فیلدهایی که واقعاً در جدول users داری
|
|
$users = User::select('id', 'first_name', 'last_name', 'email', 'mobile', 'created_at')->get();
|
|
|
|
|
|
// ۲. تبدیل به آرایه برای اکسل
|
|
$rows = $users->map(fn($user) => [
|
|
$user->id,
|
|
$user->first_name,
|
|
$user->last_name,
|
|
$user->email,
|
|
$user->mobile,
|
|
$user->created_at ? Verta::instance($user->created_at)->format('Y/m/d') : '-',
|
|
])->toArray();
|
|
|
|
// ۳. تغییر کلاس اکسل و اسم فایل
|
|
return Excel::download(new VisitsExport($rows), 'users-report-' . now()->format('Y-m-d') . '.xlsx');
|
|
}
|
|
|
|
}
|