Skip to content
Advertisement

Change column name in Laravel equivalent

I am beginner in Laravel. I have this code:

$data = Term::whereDate('begin_date', '>=', $start)->whereDate('end_date',   '<=', $end)->get(['id','name','begin_date', 'end_date']);

This is work fine.

I need change my columns result: begin_date as start_date and end_date as finish_date

How can I change it?

Advertisement

Answer

You can write it like this one

Term::whereDate('begin_date', '>=', $start)
   ->whereDate('end_date',   '<=', $end)
   ->get(['id','name','begin_date AS start_date', 'end_date As finish_date']);

Or by editing it in select method

Term::whereDate('begin_date', '>=', $start)
   ->whereDate('end_date',   '<=', $end)
   ->select('id','name','begin_date AS start_date', 'end_date As finish_date')
   ->get();
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement