laravel join 3 table belongtomany - laravel

i have 3 tables and 1 tables pivot with 3 foreign keys , i want to show all artists name with theirs job for one media but i dont have any idea how about joinning those 3 tables
Media table: media_id , media_title
artist table: artist_id, artist_name
job table: job_id, job_name
pivot table: media_id, artist_id, job_id
I have tried to do with belongsToMany between them but no result, only show the artists name but can not get theirs job name for each
Thank you to much!

Can you give the relation between these tables?
I didn't really know what you want, but try this.
\DB::table('media_artist_job')
->join('media','media.media_id','=','media_artist_job.media_id')
->join('job','job.job_id','=','media_artist_job.job_id')
->join('artist','artist.artist_id','=','media_artist_job.artist_id')
->select([
'media.medial_title',
'job.job_name',
'artist.artist_name'
])->where('media.media_id',/*The media id you want to retrieve*/)->get();
Hope it help!

Related

NIFI - How to insert distinct data from the flow and refer to that data ID in other places

I'm trying to learn NIFI so this is all new to me, I used to work with Talend and I have hard time translating to NIFI. So the main idea: For example is I have two tables in Postgresql
Table CITY :
ID (auto generated), city_name
Table PERSON :
ID (auto generated), first_name, last_name, city_id
and I have a CSV file :
first_name, last_name, city_name
Can you please explain how I can insert in tow tables from one flowfile and refer in the table PERSON to the ID of the city not the name from the table CITY.
Thank you
you could use LookupRecord to enrich each record with city id and split input in two files: matched/unmatched.
for matched you have to execute simple insert into PERSON table - because city id was found.
for unmatched you have to generate insert/upsert into CITY table and then route all those records to lookup record again.
or you could insert everything as is into temp table with structure that matches your CSV.
and then execute 2 simple sql statements:
populate missing cities from temp table
insert into person from temp table with lookup city id on the level of SQL server

Lavavel Eloquent: Relationships with 5 table

I have an app consisting of these tables
users
id
name
user_location
id
user_id
cities_id
cities
id
state_id
country_id
name
states
id
country_id
name
countries
id
name
Then how to get relationship this five table?
you have to create a many-to-many relationship between tables and use pivot table to show the relationship between table rows using foreignId

relational database in eloquent laravel

hay i have table schema like this
table transaction_fueler
id | code | user_id |user_name| ref_code | area_name
table user_community
user_id | community_id
table user_community is pivot table from table users and community
in table transaction_fueler i want to get community_id from table user_community, depends on user_id* in **transaction_fueler how to get community_id depends on user_id in table transaction_fueler ??
i stuck this.. thanks
i recommend joining the two tables and select the columns you want:
$values = DB::table('transaction_fueler')
->join('user_community', 'user_community.user_id', '=', 'transaction_fueler.user_id')
->select('transaction_fueler.*', 'user_community.community_id')->get();

What to choose to use to determine the relationship?

I have 3 tables:
table city (500 000 records)
table post (A city can have many posts)
table post_text (To store the text of the post)
table city has fields ID, NAME
table post has fields ID, CITY_ID, POST_ID
table post_text has fields TITLE, TEXT
What to use?
Polymorphic? Through? Something else?

Save on different tables using Eloquent Laravel Relationships

Hi I have 3 tables "temp_quotes", "quotes" and "quote_items"
Every quote generated goes to the "temp_quotes" table at first.
At the end of my multi-step form I need the following:
1- Receive all the quotes from the "temp_quotes" table, send it to the "quote_items" table and delete it from the "temp_quotes" table
2- Generate a new entry in the "quotes" table referencing the "users" table and
the "quote_items" table
Here is all the data and how needs to be save/removed on the tables:
temp_quotes Table
ID
BRAND
MODEL
YEAR
quotes Table:
ID
USER_ID
QUOTE_ID
quote_items Table:
ID
QUOTE_ID
BRAND
MODEL
YEAR
Any help will be appreciated.

Resources