Laravel 5 min ago with diiForHumans funtion

 

salah satu fieature date modifikasi yang saya sangat senagni dari laravel dan php adalah membuat fungsi seperti postingan beberapa hari yang lalu


namespace App\Transformers;
/**
*user transformers
*/

use App\User;
use App\Topic;

class TopicTransformer extends \League\Fractal\TransformerAbstract
{
public function transform(Topic $topic)
{
return[
'id' => $topic->id,
'title' => $topic->title,
'body' => $topic->body,
'created_at' => $topic->created_at->toDateTImeString(),
'created_at_human' => $topic->created_at->diffForHumans(),
];
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *