How to get all data for a record from table with data from another table - laravel-5

I have a table called reservations, and it contains room_id and person_id
i want to to make something like this
Reservation::find($id)->with(['person','room'])->get()
so it will return the all reservation info with that id , with person info and room info
any help ?

return Reservation::with("The table that contains the id")->find(id of record that looking for);

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

How to get specific columns from relation table in laravel?

I am trying to fetch soecific columns data from relational table but it is giving me null
$allConsignments = Consignment::query();
$allConsignments->select(['id','customer_reference'])->with('customers:name,id')->orderBy('id', 'desc')->limit(5000)->get();
When I don't use select() then it gives correct data .
like this
$allConsignments = Consignment::query();
$allConsignments->with('customers:name,id')->orderBy('id', 'desc')->limit(5000)->get()
it is working but I also need specific columns from Consignment Table. what could be the reason?
You can also do like this.
$allConsignments = Consignment::query();
$allConsignments::with('customers:name,id')->orderBy('id', 'desc')->limit(5000)->get(['id','customer_reference']);
Actually, I also need to select the foreign key column from the table on which relationship is based. for example in my case I have customer_id in consignment table so it should be like that
$allConsignments = Consignment::query();
$allConsignments->select('id','customer_reference','customer_id')->with('customers:name,id')->orderBy('id', 'desc')->limit(5000)->get();
I need to select customer_id as well

laravel join 3 table belongtomany

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!

select value form one table update value for fetched value in single query

I have two tables request and details.request table id is foreign key for details table I want I have price(321) and request_id(1819AM002) value.I want to fetch value id using request_id in request table update price field value in details table in single query.Is it possible to achieve in single query
request table
id request_id name type
1 1819AM001 XXX A
2 1819AM002 YYY A
Details table
id request_id price
1 2 133
Try this:
DB::table('details')
->join('request', 'details.request_id', 'request.id')
->where('request.request_id', '1819AM002')
->update(['price' => 321]);

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