如何自动计算背包 laravel 中的到期日期?

how to Automatically calculate expiry date in backpack laravel?

我有一个名称为月份的字段,我想要的是当用户设置月份时它自动计算 创建于 月份,然后将其上传到数据库。

PS - sorry i am new at laravel

请参阅编辑:

我的存储方法看起来像

<?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
    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;

    }