I have started learning Laravel, and I'm clearly walking with controversial relationships!
Example:
idpagina name parent 1 a null 2b1
category -
IDPGina - FK
Example:
idCategoria name parent idPagina 1c tap 2 2d 2 2
<<-
C - (B) Child
D - (C) Child
Then I have a pageinus model:
class paganus well-known {public celebration Raises children () (return $ this- & gt; Hamai ('app \ pageins', 'parent', 'idapagina'); } (& # 39; & # 39; ('Parents', '=', tap)} -> static function tree (with static :: (implode ('.', Array_fill (1, 10, 'children')) - & gt; Received ();}}
and classification model:
class categorized legendary {public function children () {$ $ -> $ many-app \ categoria ',' parent ',' idCategoria '); } (& # 39; & # 39; ('Parents', '=', tap)} -> static function tree (with static :: (implode ('.', Array_fill (1, 10, 'children')) - & gt; Received ();}}
And now I just want to get involved in both tables!
Edit
Well, I just suggested Stephen Lewis's code! But now I can not get multi-level as I want, here is the blade code
@foreach ( $ Page as $ page) & lt; h1 & gt; {{$ pagina - & gt; ; NomePag}} & lt; / h1 & gt; @foreach ($ pagina - & gt; children are called $ child) & lt; h3 & gt; {{$ child - & gt; nomePag}} & lt; >
Categoria
> Add to class:
public function page () {return $ it-> gt; ('page', 'idpagina'); }
You can also specify it on the other side of the relationship by adding it to the page
category:
public function categories () {Return $ this- & gt; Hamai ('category', 'idapagina'); }
More information about working with supernatural relationships is available.
No comments:
Post a Comment