C
C
chelkaz2016-03-25 02:15:08
Laravel
chelkaz, 2016-03-25 02:15:08

How to avoid conflict over method and field names in a table?

I noticed that if there is a table with a field for example field
Then if in the model for example model make a relation with a method called field and then get

$elements = Element::with('field')->orderBy('id','desc')->paginate(15);

And in the view, get the associated table $elements->field That's fucked up, because it will simply give the field field from the elements
table And there is confusion with the names in the head. Can I somehow indicate here $elements-> field that this is not a field, but a linked table?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kuznetsov, 2016-03-25
@dima9595

I propose to add the name of the table to the field field, so that it turns out field_element. And in the template to access this variable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question