I'm wondering how to get the correct id on join without specifying the table or 'as' in the select part of the query.
I have two models, Tickets and Users:
Tickets.php has (pseudo-code): public function getUrl() { return 'ticket/{ $this->id }'; }
If I do: Tickets::join('Users'), mysql returns a table with two id's, so Ticket::getUrl() returns
ticket/{ users.id }
instead of:
ticket/{ tickets.id }
I'm wondering if there's a way to cajigger the model to make sure it returns $this->ticket.id and not any other id.
use a select statement to take only the fields you need.
Tickets:select('tickets_table.*, users_table.name as user_name')->join('users_table', 'tickets_table.owner_id', '=', 'users_table.id');
currently there's no way of doing this automatically .
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community