Php Laravel 5.4我如何获得每月新申请总数
我在我的申请表,我会得到所有报告的总新申请每月 以下是我的应用程序表结构:Php Laravel 5.4我如何获得每月新申请总数,php,laravel,laravel-5,laravel-5.4,Php,Laravel,Laravel 5,Laravel 5.4,我在我的申请表,我会得到所有报告的总新申请每月 以下是我的应用程序表结构: public function up() { Schema::create('applications', function (Blueprint $table) { //$table->increments('id'); $table->string('application_number')->primary(); $table->str
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是新手,尤其是在后端使用模型和控制器。所以我在寻求帮助。
提前感谢。从您的刀片服务器或其他地方获取
日期,具体取决于您
但在本例中,它将来自刀片的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>
对于查询,它应该是这样的:
$orders = DB::table('orders')
->whereDate('created_at','>=', $datefrom)
->whereDate('created_at', '<=', $dateto)
->get();
$orders=DB::table('orders'))
->whereDate('created_at','>=',$datefrom)
->whereDate('created_at',您可以使用Carbon
操作时间戳以获得定期报告,还可以使用Query Builder
,以便在以下情况下方便地使用:$application=DB::table('applications')->whereMonth('created_at','8')->get();因此,我将查询每个月和其他月份,并为它们分配变量,并根据标签显示在数据集上?您可以使用Carbon::now()->startOfMonth()
获取当月的第一天和Carbon::now()->endOfMonth()代码>以获取最后一天。它也有几天、几周和几年!所以它真的很有帮助,就像:$application_aug=DB::table('applications')->whereMonth('created_at','Carbon::now()->eightOfMonth();')->count();像那样?我会发布一个答案,这样看起来会更好。:)谢谢你!成功了!所以你也是菲律宾人。我还是个学生,想探索和学习更多关于MVC框架和OOP的知识。很高兴它成功了!是的,我也是菲律宾人,还是像你一样的学生D与stackoverflow保持联系。他们对与Laravel有关的问题有很好的答案,哈哈。我可以把你添加到facebook上吗?哈哈哈
$orders = DB::table('orders')
->whereDate('created_at','>=', $datefrom)
->whereDate('created_at', '<=', $dateto)
->get();