Support the ongoing development of Laravel.io →
posted 2 years ago
Last updated 2 years ago.
0

you wanted to retrieve all other users who is having interests same as current user ?

vipankumar87 liked this reply

1

@suhailparad right I tried this solution https://stackoverflow.com/questions/70986081/why-extra-query-running-in-eloquent

but it is not good executing many queries but i can do in single query but i want to do it in laravel way not in pure sql

0

You can write a relation in Interest::class to fetch all the users with same interest.

0

can you please help me out on this or can give me idea how i can do this, i searching and try to accomplish this but i am unable to do

Last updated by @vipankumar87 2 years ago.
0

please share your database structure

0

Interest Table create table interests ( id bigserial primary key, name varchar(255) default ''::character varying not null, post_count bigint default '0'::bigint, created_at timestamp(0), updated_at timestamp(0), deleted_at timestamp(0) );

User_interest Pivot Table

create table user_interest ( user_id bigint not null constraint user_interest_user_id_foreign references users on delete cascade, interest_id bigint not null constraint user_interest_interest_id_foreign references interests on delete cascade );

User Table

create table users ( id bigserial primary key, name varchar(255) not null, email varchar(255) not null constraint users_email_unique unique, email_verified_at timestamp(0), password varchar(255) not null, remember_token varchar(100), created_at timestamp(0), updated_at timestamp(0), username varchar(255) not null constraint users_username_unique unique, profile_status varchar(255) default '0'::character varying );

Last updated by @vipankumar87 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.