Reputation: 868
<div class="form-group clearfix">
<label for="dob_month" class="sr-only">Month</label>
<select name = "month" id="m" class="form-control" value="{{Auth::user()->dob['month']}}"/>
<option value="">Month</option>
@for ($month = 1; $month <= 12 ; $month++)
<option value = "{{ $month }}">{{ $month }}</option>
@endfor
</select>
</div>
Upvotes: 1
Views: 1521
Reputation: 38952
Where dob
is a field stored in the Database as a date, and a record is queried that contains the field through the Eloquent model it gets implicitly converted to an instance of Carbon\Carbon
.
Note that the month
property cannot be retrieved as using array index access on the instance but only via object property getters as:
Auth::user()->dob->month
Upvotes: 1
Reputation: 13669
get month value like this way :
\Carbon\Carbon::createFromFormat('Y-m-d',Auth::user()->dob)->format('m')
<div class="form-group clearfix">
<label for="dob_month" class="sr-only">Month</label>
<select name = "month" id="m" class="form-control"/>
<option value="">Month</option>
@for ($month = 1; $month <= 12 ; $month++)
@if($month==\Carbon\Carbon::createFromFormat('Y-m-d',Auth::user()->dob)->format('m'))
<option value = "{{ $month }}" selected>{{ $month }}</option>
@else
<option value = "{{ $month }}">{{ $month }}</option>
@endif
@endfor
</select>
</div>
Upvotes: 1
Reputation:
<select name = "month" id="m" class="form-control" value=""/>
<option value=" {{\Carbon\Carbon::parse(Auth::user()->dob)->format('m')}}">
{{\Carbon\Carbon::parse(Auth::user()->dob)->format('m')}}
</option>
@for ($month = 1; $month <= 12 ; $month++)
<option value = "{{ $month }}">{{ $month }}</option>
@endfor
</select>
Try This It Will Work for You
Upvotes: 1