Laravel 5.4 как я могу получить сумму от общего числа новых заявок в месяц

У меня есть в моем заявлении, что я буду получать все отчеты общего количества новых заявлений в месяц.

Вот моя структура таблицы приложений:

public function up()
{
Schema::create('applications', function (Blueprint $table) {
//$table->increments('id');
$table->string('application_number')->primary();
$table->string('applicant_id');
//$table->string('reference_number', 50);
$table->string('business_name');
$table->string('business_nature');
$table->string('location_street');
$table->string('location_building')->nullable();
$table->string('location_barangay');
$table->string('location_district');
$table->string('landmarks')->nullable();
$table->string('owner_fn');
$table->string('owner_mn')->nullable();
$table->string('owner_ln');
$table->string('ar_fn');
$table->string('ar_mn')->nullable();
$table->string('ar_ln');
$table->string('landline')->nullable();
$table->string('cellphone_number')->nullable();
$table->string('occupancy_type');
//$table->string('cluster_no', 50);
$table->string('land_area')->nullable();
$table->string('no_floor')->nullable();
$table->string('floor_area')->nullable();
$table->string('no_employees')->nullable();
$table->string('requirements_1')->nullable();
$table->string('requirements_2')->nullable();
$table->string('requirements_3')->nullable();
$table->string('requirements_4')->nullable();
$table->string('applicant_name');
$table->string('status');
$table->string('application_type');
$table->date('expired_at');
$table->timestamps();
$table->softDeletes();
});
}

и вот код в моем контроллере:

public function index()
{
$applications = DB::table('applications')->sum('created_at');
$inspections = DB::table('for_inspections')->sum('created_at');
$certifications = DB::table('certification')->sum('created_at');

$chart = Charts::multi('bar', 'material')
// Setup the chart settings
->title("Monthly Report")
// A dimension of 0 means it will take 100% of the space
->dimensions(0, 400) // Width x Height
// This defines a preset of colors already done:)
->template("material")
// You could always set them manually
// ->colors(['#2196F3', '#F44336', '#FFC107'])
// Setup the diferent datasets (this is a multi chart)
->dataset('New Applications', [5,20,100,0,0,0,0,0,0,0,0,0])
->dataset('Total Inspection', [15,30,80,0,0,0,0,0,0,0,0,0])
->dataset('Certified', [25,10,40,0,0,0,0,0,0,0,0,0])
// Setup what the values mean
->labels(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec']);
return view('admin-dashboard.reports_home', ['chart' => $chart]);
}

Здесь нет ошибок или проблем. Я просто не знаю, с чего начать, потому что я новичок в Laravel, особенно в бэкэнде, использующем модель и контроллер. Поэтому я ищу помощи.
Заранее спасибо.

1

Решение

Получить datefrom а также dateto от вашего клинка или где-то еще, зависит от вас.

Но в этом примере это будет от лезвия select пометить имя как period:

<select name="period" id="period" class="form-control">
<option></option>
<option>Daily</option>
<option>Weekly</option>
<option>Monthly</option>
<option>Yearly</option>
</select>

Таким образом, он решит, как он будет отображать отчеты, будь то Ежедневно, Еженедельно, Ежемесячно и Ежегодно.

Внутри контроллера я установил пример:

            if($period == 'Daily'){
$datefrom = Carbon::now()->startOfDay();
$dateto = Carbon::now()->endOfDay();
}
elseif ($period == 'Weekly') {
$datefrom = Carbon::now()->startOfWeek();
$dateto = Carbon::now()->endOfWeek();
}
elseif ($period == 'Monthly') {
$datefrom = Carbon::now()->startOfMonth();
$dateto = Carbon::now()->endOfMonth();
}
elseif ($period == 'Yearly'){
$datefrom = Carbon::now()->startOfYear();
$dateto = Carbon::now()->endOfYear();
}

А для запроса это будет примерно так:

 $orders = DB::table('orders')
->whereDate('created_at','>=', $datefrom)
->whereDate('created_at', '<=', $dateto)
->get();
2

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector