Diego Cespedes Diego Cespedes - 1 year ago 85
PHP Question

Laravel 5.2 - calculate expire date of my post

i would like that user can choice the expire of a post, for example in the form of create post i will insert a input select option with: 24h, 48h, 72h.

My question, i need store the date of expire in my database, how can i calculate it?

I know that i can get the time of creation post like this:

VIEW - MY form have a input like this

<select name="expire_date">
<option value="24">24h</option>
<option value="48">48h</option>
<option value="72">72h</option>


// get the current time
$current = Carbon::now();
$current = new Carbon();
// maybe so ??
$expire_date = $current + $request->input('expire_date')

i would like create a variable with value of expire date post, i need store this data so i can show in my index list.

Thank you for your support!

Answer Source

You can do something like that on your controller: assuming you have Input::all() on yoit request variable.

$expire_date = Carbon::now()->addHours($request->expire_date);  

as you can see on carbon doc

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download