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

时间:2017-08-18 06:50:15

标签: laravel backpack-for-laravel

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

  

PS - 抱歉,我是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;
}

}

2 个答案:

答案 0 :(得分:1)

假设您指的是月份(即每月付款)

您可以在商店方法中执行此操作,例如:

$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

答案 1 :(得分:0)

    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;

    }