fix: update admin dashboard
This commit is contained in:
@@ -7,12 +7,10 @@ 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;
|
||||
|
||||
@@ -21,45 +19,70 @@ 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();
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| دادههای نمودار
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
$chartLabels = [];
|
||||
$chartValues = [];
|
||||
|
||||
for ($i = 9; $i >= 0; $i--) {
|
||||
|
||||
$date = Carbon::now()
|
||||
->subDays($i);
|
||||
|
||||
$chartLabels[] = Verta::instance($date)
|
||||
->format('Y/m/d');
|
||||
|
||||
// فعلاً برای تست
|
||||
$chartValues[] = rand(5, 100);
|
||||
}
|
||||
|
||||
return view('admin.dashboard', compact(
|
||||
'usersCount',
|
||||
'toursCount',
|
||||
'flightsCount',
|
||||
'airportsCount',
|
||||
'commentsCount',
|
||||
'favoritesCount'
|
||||
'favoritesCount',
|
||||
'chartLabels',
|
||||
'chartValues'
|
||||
));
|
||||
}
|
||||
|
||||
public function exportExcel()
|
||||
{
|
||||
// ۱. لیست کاربران با فیلدهایی که واقعاً در جدول users داری
|
||||
$users = User::select('id', 'first_name', 'last_name', 'email', 'mobile', 'created_at')->get();
|
||||
$users = User::select(
|
||||
'id',
|
||||
'first_name',
|
||||
'last_name',
|
||||
'email',
|
||||
'mobile',
|
||||
'created_at'
|
||||
)->get();
|
||||
|
||||
|
||||
// ۲. تبدیل به آرایه برای اکسل
|
||||
$rows = $users->map(fn($user) => [
|
||||
$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') : '-',
|
||||
$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');
|
||||
return Excel::download(
|
||||
new VisitsExport($rows),
|
||||
'users-report-' . now()->format('Y-m-d') . '.xlsx'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user