Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

Try putting the columns in your get(). Like: ->get (['jobs.*'])

Last updated 1 year ago.
0

jazpur said:

Try putting the columns in your get(). Like: ->get (['jobs.*'])

tried, no help.

Last updated 1 year ago.
0

It seems that laravel is putting the 'locations.id' as the $job->id instead of 'jobs.id', maybe a bug?

Last updated 1 year ago.
0

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

Last updated 1 year ago.
0

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']);
Last updated 1 year ago.
0

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);
Last updated 1 year ago.
0

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?

Last updated 1 year ago.
0

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.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ammont ammont Joined 10 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.