2017-08-18 18 views
0

私が望むのは月のフィールドです。ユーザーが月を自動設定した場合、で作成した月は月に作成され、データベースにアップロードされます。バックパック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; 
} 

}

+0

まさにあなたは月とのcreated_atフィールドで計算したいですか?例を挙げてください。 – Jerodev

+0

実際には、私のテーブルには、名前がcreated_atであり、expire_atである他のカラムがあります...新しいユーザ登録バックパックがcreate_atカラムを自動的に埋めるように、ユーザに依存するexpire_atカラムを満たす必要があります月 –

答えて

0

のように見えます金額(月払いの場合)

あなたの店の方法すなわちでこのようにそれを行うことができます。

$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 
+0

それは列にnullを表示しています –

+0

あなたのメールIDを教えてください..私はそこにあなたのプロジェクトをお送りします –

+0

どのフィールドにnullが表示されますか?申し訳ありませんが、私はそれがサイトのルールによって割り当てられていないと思う – aaron0207

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; 

    } 
関連する問題