I would wan to display month and data for payment_date only in a foreach loop in view.blade.php.
@foreach ($alert as $key=>$data)
<tr>
<td>{{ $key }}</td>
<td>{{ $data->tenant_name}}</td>
<td>{{ $data->property_name}}</td>
<td>RM {{ $data->amount}}</td>
<td>{{ $data->payment_date }}</td>
<td><span >{{ $data->status }}</span></td>
<td><a href="{{ route('view.email', $data->tenant->id) }}" title="Send Email"> <i ></i> </a>
</td>
</tr>
@endforeach
Hereby I include the datatype:
CodePudding user response:
Short way (not recommended)
@foreach ($alert as $key=>$data)
<tr>
<td>{{ $key }}</td>
<td>{{ $data->tenant_name}}</td>
<td>{{ $data->property_name}}</td>
<td>RM {{ $data->amount}}</td>
<td>{{ \Carbon\Carbon::createFromFormat('Y-m-d', $data->payment_date)->format('m-d') }}</td>
<td><span >{{ $data->status }}</span></td>
<td><a href="{{ route('view.email', $data->tenant->id) }}" title="Send Email"> <i ></i> </a>
</td>
</tr>
@endforeach
Laravel way (Recommended)
Add cast to the eloquent model class.
protected $casts = [
'payment_date' => 'date',
];
after that you can do this
@foreach ($alert as $key=>$data)
<tr>
<td>{{ $key }}</td>
<td>{{ $data->tenant_name}}</td>
<td>{{ $data->property_name}}</td>
<td>RM {{ $data->amount}}</td>
<td>{{ $data->payment_date->format('m-d') }}</td>
<td><span >{{ $data->status }}</span></td>
<td><a href="{{ route('view.email', $data->tenant->id) }}" title="Send Email"> <i ></i> </a>
</td>
</tr>
@endforeach