Laravel pivot table joined with pivot table - laravel

I have following Database Tables
User
-idUser
Products
-idProducts
Product_Collector
-Product_CollectorID
-idProducts (foreign)
-idUser (foreign)
Ticket
-idTicket
-Product_CollectorID
Currently I'm modeling all these Database Tables in Laravel.
But I'm struggeling with the function to get the Products associated with the Tickets.
Do I have to create a model for the Product_Collector? Or is there any other good solution?

Related

Include related custom table in Dynamics 365 Plugin Registration Tool step

I have created a ServiceEndpoint with create, update and delete steps for the accounts table. The accounts table has a many-to-many relationship with a custom table. How do I create a step that will include the relationship records when changes are made to the accounts table?
I tried finding the relationship table in Dataverse, but it's not part of the list of tables.

How to link two different tables in one relational table in laravel

I have two different tables client and admin, i want to add relation in one table post has many relation. Overall scenario is client and admin can multiple posts. How can do it in laravel?

Laravel Many-Many Relationship with extra data

I have a many-many relationship in my Laravel application, Courses and Users, and users can enroll in a course with my Enrollments table. My Enrollments table functions as the many-many table for Courses and Users. A user can enroll in a course one time.
My idea is that Enrollments will function more than just a many-many table, and store info like the payment amount, expiration date of the enrollment, etc. However, in Laravel Nova (my admin dashboard), I can't make the HasOne:: relationship work for the Enrollments table. It's just ugly IDs that I never want shown. Help.

Laravel Eloquent triple Relationship

I am stuck in situation where I need relation between 3 different tables. My tables are companies, products and Roles. Companies can assign multiple Roles to multiple products. The problem is Companies do not have any relationship with products. Products are added through admin.
Currently I have made a table company_product_role with structure company_id, product_id and role_id, the problem is how to make eloquent relation for insertion and retrieval. Either I am doing it correct or there is simple solution for it?
Any help will be appreciated.

laravel Eloquent ORM multiple table insert

How would i make a single request to insert in multiple tables using laravel Eloquent ORM relationship .ie
Table 1 : users
id
name
email
Table 2 : posts
id
user_id
content
Table 3 : Image
id
user_id
post_id
image_name
relationship
Table users id references user_id in other two tables .
Table posts has One To Many relation with users.
Table images has One To Many relation with users and post ie it can be shared with other users and on other posts.
So that when one makes a post insert ,it should insert the record in the tables with a single query.
This is one way of doing it:
$post = (new Post)->fill($request->all()->toArray())->user()->associate(Auth::user())->save();
As for the image, the Post model should have a model event such as static::created to handle the image upload and manipulation.
Or to make more sense, a model event in the Post model should trigger another model event from the Image model.
->toArray() may be optional, I can't test it here where I'm now.

Resources