如何在Backback laravel中自动计算过期日期?
我有一个名为month的字段,我想要的是当用户设置在month创建的月份时自动计算,然后将其上传到数据库 对不起,我是新来的 请参见编辑: 我的存储方法看起来像如何在Backback laravel中自动计算过期日期?,laravel,backpack-for-laravel,Laravel,Backpack For Laravel,我有一个名为month的字段,我想要的是当用户设置在month创建的月份时自动计算,然后将其上传到数据库 对不起,我是新来的 请参见编辑: 我的存储方法看起来像 <?php namespace App\Http\Controllers\Admin; use Backpack\CRUD\app\Http\Controllers\CrudController; // VALIDATION: change the requests to match your own file names
<?php
namespace App\Http\Controllers\Admin;
use Backpack\CRUD\app\Http\Controllers\CrudController;
// VALIDATION: change the requests to match your own file names if you need
form validation
use App\Http\Requests\ClientsRequest as StoreRequest;
use App\Http\Requests\ClientsRequest as UpdateRequest;
use Carbon\Carbon;
class ClientsCrudController extends CrudController
{
public function setup()
{
$this->crud->setModel('App\Models\Clients');
$this->crud->setRoute(config('backpack.base.route_prefix') . '/clients');
$this->crud->setEntityNameStrings('clients', 'clients');
$this->crud->setFromDb();
}
public function store(StoreRequest $request)
{
// your additional operations before save here
$start_day = Carbon::parse($request->created_at);
$expiry_day = $start_day->addMonths($request->month);
$request->input($expiry_day);
$redirect_location = parent::storeCrud($request);
// your additional operations after save here
// use $this->data['entry'] or $this->crud->entry
return $redirect_location;
}
public function update(UpdateRequest $request)
{
// your additional operations before save here
$redirect_location = parent::updateCrud($request);
// your additional operations after save here
// use $this->data['entry'] or $this->crud->entry
return $redirect_location;
}
假设您的意思是月数(即每月付款)
您可以在存储方法中这样做,即:
$start_day = Carbon::parse($request->created_at); //get a carbon instance with created_at as date
$expiry_day = $start_day->addMonths($request->user_selected_months); //add X months to created_at date
您想用一个月和创建的_at字段计算什么?请举个例子。事实上,先生,我的表格中有一列的名字是在创建的,另一列的名字是在过期的。。。因此,当新用户注册背包时,自动填写“创建在”列,这样我就必须填写“过期在”列,这取决于用户monthtell我您的电子邮件id先生。。我会将我的项目发送给你,哪个字段显示为空?抱歉,我认为网站规则不允许使用实际控制人方法代码更新您的问题变量$request->month
是一个月吗?七月怎么样?还是一个月的金额?大约5个月。哪个变量显示为空?我不明白这行$request->input($expiration\u day)这里会发生什么?只是试着忘掉那件事,先生
public function store(StoreRequest $request) {
date_default_timezone_set('asia/calcutta');
$month = $request->month;
$expiry_date = Carbon::now()->addMonths($month);
$request['expiry_date'] = $expiry_date;
}