Mutators and Accessors in Laravel Set file path in model public function getFilePathAttribute($file_path) { if(!empty($file_path)) { return $filepath = URL::to('/') . '/upload/' . $file_path; /* return asset('/upoad/' . $file_path); */ } } Set created time ago in model protected $appends = ["created_time_ago"]; public function getCreatedTimeAgoAttribute() { $created_at = $this->attributes['created_at']; // Convert the date/time to a Carbon instance $carbonCreatedAt = Carbon::parse($created_at); // Get the "time ago" format $timeAgo = $carbonCreatedAt->diffForHumans(); ...
We provide knowledgeable blogs related to php, jQuery, html, css, wordpress, woocommerce, cordova app with examples in 2021.