php - Custom function in Select query Laravel

Solution:

In your Job model

public function getDateAttribute($value)
{
    return Carbon::parse($value)->isoFormat('dddd');
}

Write like

$data = Job::select('id', 'customer_id', 'date','time')->get();

Answer

Solution:

Note:custome function inside select query.This is possible with model only.without model its not working.

$posts = TMCPost::select('tmc_posts.*', 'tmc_posts.id as encrypted_post_id')->get();

Inside Model

public function getEncryptedPostIdAttribute($value)
{
    return custom_function('encrypt',$value);
}

For More Brief Examples Follow Source: https://expertsuggestion.com/tutorial/laravel/how-to-use-custom-function-inside-select-query-laravel

Answer

Solution:

$data = DB::table('jobs')
        ->select('id', 'customer_id', \DB::raw("DAYNAME(date)"),'time')
        ->get();

DAYNAME function will return the name of the day at the specific date. Here's a link!.

Source