I have this query
$sales = Sales::join('customer', 'customer.id', '=', 'sales.customer_id')
->join('cashier', 'cashier.id', '=', 'sales.cashier_id')
->first();
how can i select each table with prefix so i can call like this :
with my query above, i only get one name row because each table have same column name name
, what
i want is to give prefixed in each table i call like customer_
, cashier_
, sales_
the result what i expect is like this
customer_name
customer_address
customer_phone
cashier_name
cashier_another_column
cashier_another_column2
sales_date
sales_another_column
sales_another_column2
the answer is you cannot do that. i usually only alias the same column name and get the rest with *
. so your required to alias all same column name for solve the conflict
Sales::join('customer', 'customer.id', '=', 'sales.customer_id')
->join('cashier', 'cashier.id', '=', 'sales.cashier_id')
->select(['*', 'customer.name as customer_name', 'cashier.name as cashier_name'])
->get();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With