V
V
Viktor K2019-09-03 19:30:41
Laravel
Viktor K, 2019-09-03 19:30:41

Creating relationships in Laravel via table?

There are 2 tables of the form:

CREATE TABLE events (
  id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
    title varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (id)
)

CREATE TABLE objects(
  id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  title varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (id)
)

I want to store the relationship between them in a third table like
CREATE TABLE object_to_events (
  id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  eventId bigint(20) UNSIGNED NOT NULL,
  objectId bigint(20) UNSIGNED NOT NULL,
  PRIMARY KEY (id)
)

A couple of questions - is it possible to make such a relation in the model using Laravel? If so, how? My brains were not enough to figure out the docks
Or maybe there is some kind of regular way to make such relationships that I don't know

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
NubasLol, 2019-09-03
@vuldozer

https://laravel.com/docs/6.0/eloquent-relationship...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question