Try putting the columns in your get(). Like: ->get (['jobs.*'])
jazpur said:
Try putting the columns in your get(). Like: ->get (['jobs.*'])
tried, no help.
It seems that laravel is putting the 'locations.id' as the $job->id instead of 'jobs.id', maybe a bug?
Ok, I had the same problem and adding columns to the get() solved it for me. This my code:
$collection = Order::with('athlete')
->join('athletes', 'athletes.id', '=', 'orders.athlete_id')
->where('athletes.lastname', 'LIKE', '%'.$search.'%')
->orWhere('orders.id', '=', $search)
->get(['orders.*']);
Omitting the column array in the get statement returns identical ID's. This worked for me
You can try to execute the sql query under phpmyadmin, you should see that the resulting table has several columns with the same "id" name. Only the first is used by Laravel as it is impossible to know for which model is each "id" column. So you may have to list the needed fields and the needed id, using " as " at least for the id. I had a similar problem but with Eloquent both for "Id" and "created_at", and I used something like that:
$results = User::find($id)->comments()->approved()->orderBy('reviews.created_at', 'desc')->paginate(10,
['reviews.created_at', 'reviews.etoiles', 'reviews.user_id as username_id', 'reviews.commentaire', 'products.name', 'product_id']);
Specify a table alias in your join, like so (using jazpur's example):
$collection = Order::with('athlete')
->join('athletes as a', 'a.id', '=', 'orders.athlete_id')
->where('a.lastname', 'LIKE', '%'.$search.'%')
->orWhere('orders.id', '=', $search);
gilr said:
You can try to execute the sql query under phpmyadmin, you should see that the resulting table has several columns with the same "id" name. Only the first is used by Laravel as it is impossible to know for which model is each "id" column. So you may have to list the needed fields and the needed id, using " as " at least for the id. I had a similar problem but with Eloquent both for "Id" and "created_at", and I used something like that:
$results = User::find($id)->comments()->approved()->orderBy('reviews.created_at', 'desc')->paginate(10, ['reviews.created_at', 'reviews.etoiles', 'reviews.user_id as username_id', 'reviews.commentaire', 'products.name', 'product_id']);
Isn't it something that laravel should handle?
thepsion5 said:
Specify a table alias in your join, like so (using jazpur's example):
$collection = Order::with('athlete') ->join('athletes as a', 'a.id', '=', 'orders.athlete_id') ->where('a.lastname', 'LIKE', '%'.$search.'%') ->orWhere('orders.id', '=', $search);
this encourages error.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community