Reputation: 4997
I have table called tickets with p.k. id and ticket number (i.e. TK0001)
I am using a laravel and for some reason I am required to get the ticket_number as id in response.
Below is my query
SELECT CAST(ticket_number as varchar) as id from tickets.
Below is my response
{
"status": 200,
"data": {
"current_page": 1,
"data": [
{
"id": 0
},
{
"id": 0
}
],
"first_page_url": "http://localhost:8000/dm/v2/report/preview/data?page=1",
"from": 1,
"last_page": 1,
"last_page_url": "http://localhost:8000/dm/v2/report/preview/data?page=1",
"next_page_url": null,
"path": "http://localhost:8000/dm/v2/report/preview/data",
"per_page": 100,
"prev_page_url": null,
"to": 2,
"total": 2
}
}
If you see it's returning me "id": 0
But it returns me the ticket number when using the alias name different like ids.
Here are the data from my table
id ticket_number
22021 "TK33412"
22022 "TK15961"
22023 "TK15840"
22024 "TK33413"
22025 "TK33416"
22026 "TK33415"
here is my query
$mainSelect = "CAST(ticket_number as varchar) as id ";
$query = \App\Models\DM\LeadsTickets::selectRaw($mainSelect);
$queryResponse = $query->paginate($perPage , $page);
return $queryResponse;
Upvotes: 0
Views: 39