<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="http://178.140.10.58:8080/lib/exe/css.php?s=feed" type="text/css"?>
<rdf:RDF
    xmlns="http://purl.org/rss/1.0/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
    xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel rdf:about="http://178.140.10.58:8080/feed.php">
        <title>Библиотека знаний - php:laravel</title>
        <description>Заметки IT программиста</description>
        <link>http://178.140.10.58:8080/</link>
        <image rdf:resource="http://178.140.10.58:8080/lib/exe/fetch.php?media=wiki:dokuwiki.svg" />
       <dc:date>2026-04-16T23:30:38+00:00</dc:date>
        <items>
            <rdf:Seq>
                <rdf:li rdf:resource="http://178.140.10.58:8080/doku.php?id=php:laravel:lumen"/>
                <rdf:li rdf:resource="http://178.140.10.58:8080/doku.php?id=php:laravel:relations"/>
            </rdf:Seq>
        </items>
    </channel>
    <image rdf:about="http://178.140.10.58:8080/lib/exe/fetch.php?media=wiki:dokuwiki.svg">
        <title>Библиотека знаний</title>
        <link>http://178.140.10.58:8080/</link>
        <url>http://178.140.10.58:8080/lib/exe/fetch.php?media=wiki:dokuwiki.svg</url>
    </image>
    <item rdf:about="http://178.140.10.58:8080/doku.php?id=php:laravel:lumen">
        <dc:format>text/html</dc:format>
        <dc:date>2019-06-30T20:12:04+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Lumen</title>
        <link>http://178.140.10.58:8080/doku.php?id=php:laravel:lumen</link>
        <description>&lt;div class=&quot;tags&quot;&gt;&lt;span&gt;
	&lt;a href=&quot;http://178.140.10.58:8080/doku.php?id=tag:lumen&amp;amp;do=showtag&amp;amp;tag=lumen&quot; class=&quot;wikilink1&quot; title=&quot;tag:lumen&quot; rel=&quot;tag&quot;&gt;lumen&lt;/a&gt;,
	&lt;a href=&quot;http://178.140.10.58:8080/doku.php?id=tag:laravel&amp;amp;do=showtag&amp;amp;tag=laravel&quot; class=&quot;wikilink1&quot; title=&quot;tag:laravel&quot; rel=&quot;tag&quot;&gt;laravel&lt;/a&gt;,
	&lt;a href=&quot;http://178.140.10.58:8080/doku.php?id=tag:framework&amp;amp;do=showtag&amp;amp;tag=framework&quot; class=&quot;wikilink1&quot; title=&quot;tag:framework&quot; rel=&quot;tag&quot;&gt;framework&lt;/a&gt;,
	&lt;a href=&quot;http://178.140.10.58:8080/doku.php?id=tag:php&amp;amp;do=showtag&amp;amp;tag=php&quot; class=&quot;wikilink1&quot; title=&quot;tag:php&quot; rel=&quot;tag&quot;&gt;php&lt;/a&gt;
&lt;/span&gt;&lt;/div&gt;

&lt;h1 class=&quot;sectionedit1&quot; id=&quot;lumen&quot;&gt;Lumen&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;
 &lt;a href=&quot;https://github.com/LightAir/Lumen-docs&quot; class=&quot;urlextern&quot; title=&quot;https://github.com/LightAir/Lumen-docs&quot; rel=&quot;ugc nofollow&quot;&gt;https://github.com/LightAir/Lumen-docs&lt;/a&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Lumen&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;lumen&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;38-&amp;quot;} --&gt;</description>
    </item>
    <item rdf:about="http://178.140.10.58:8080/doku.php?id=php:laravel:relations">
        <dc:format>text/html</dc:format>
        <dc:date>2024-10-10T02:37:58+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Отношения / Relations</title>
        <link>http://178.140.10.58:8080/doku.php?id=php:laravel:relations</link>
        <description>&lt;div class=&quot;tags&quot;&gt;&lt;span&gt;
	&lt;a href=&quot;http://178.140.10.58:8080/doku.php?id=tag:laravel&amp;amp;do=showtag&amp;amp;tag=laravel&quot; class=&quot;wikilink1&quot; title=&quot;tag:laravel&quot; rel=&quot;tag&quot;&gt;laravel&lt;/a&gt;,
	&lt;a href=&quot;http://178.140.10.58:8080/doku.php?id=tag:framework&amp;amp;do=showtag&amp;amp;tag=framework&quot; class=&quot;wikilink1&quot; title=&quot;tag:framework&quot; rel=&quot;tag&quot;&gt;framework&lt;/a&gt;,
	&lt;a href=&quot;http://178.140.10.58:8080/doku.php?id=tag:php&amp;amp;do=showtag&amp;amp;tag=php&quot; class=&quot;wikilink1&quot; title=&quot;tag:php&quot; rel=&quot;tag&quot;&gt;php&lt;/a&gt;
&lt;/span&gt;&lt;/div&gt;

&lt;p&gt;
.
&lt;/p&gt;

&lt;h1 class=&quot;sectionedit1&quot; id=&quot;отношения_relations&quot;&gt;Отношения / Relations&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;
 Отношения «один к одному»
&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;
 Отношение «один ко многим»
&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;
 Имеет отношение «один из многих»
&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;
 Отношения HasOneThrough и HasManyThrough
&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;
 Отношение «многие ко многим»
&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;
 Полиморфные отношения
&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;
 Полиморфный Один к одному
&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;
 Полиморфный Один Ко Многим
&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;
 Полиморфный Один из Многих
&lt;/div&gt;&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;
 Полиморфный Многие-К-Многим
&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;\u041e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \/ Relations&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f_relations&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;49-641&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;ссылки&quot;&gt;Ссылки&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt;
 &lt;a href=&quot;https://habr.com/ru/articles/494658/&quot; class=&quot;urlextern&quot; title=&quot;https://habr.com/ru/articles/494658/&quot; rel=&quot;ugc nofollow&quot;&gt;Используем трейты для полиморфных связей&lt;/a&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;\u0421\u0441\u044b\u043b\u043a\u0438&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;\u0441\u0441\u044b\u043b\u043a\u0438&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;642-790&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit3&quot; id=&quot;отношения_один_к_одному&quot;&gt;Отношения «один к одному»&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
&lt;a href=&quot;http://178.140.10.58:8080/lib/exe/detail.php?id=php%3Alaravel%3Arelations&amp;amp;media=php:laravel:one-to-one.png&quot; class=&quot;media&quot; title=&quot;php:laravel:one-to-one.png&quot;&gt;&lt;img src=&quot;http://178.140.10.58:8080/lib/exe/fetch.php?w=600&amp;amp;tok=ae93a0&amp;amp;media=php:laravel:one-to-one.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; width=&quot;600&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;pre class=&quot;code bash&quot;&gt;$ php artisan make:model Tenant 
$ Php artisan make:model Rent&lt;/pre&gt;
&lt;pre class=&quot;code php&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;&amp;lt;?php&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;namespace&lt;/span&gt; App\Models&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;use&lt;/span&gt; Illuminate\Database\Eloquent\Model&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; Tenant &lt;span class=&quot;kw2&quot;&gt;extends&lt;/span&gt; Model
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;co4&quot;&gt;/**
    * Get the rent of a Tenant
    */&lt;/span&gt;
    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; rent&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; 
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;hasOne&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Rent&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;co1&quot;&gt;//return $this- &amp;gt;hasOne(Rent::class, &amp;quot;custom_key&amp;quot;);&lt;/span&gt;
        &lt;span class=&quot;co1&quot;&gt;//return $this-&amp;gt;hasOne(Rent::class, &amp;quot;custom_key&amp;quot;, &amp;quot;other_key&amp;quot;); &lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt; 
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;re0&quot;&gt;$rent&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; Tenant&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;rent&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;\u041e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u00ab\u043e\u0434\u0438\u043d \u043a \u043e\u0434\u043d\u043e\u043c\u0443\u00bb&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f_\u043e\u0434\u0438\u043d_\u043a_\u043e\u0434\u043d\u043e\u043c\u0443&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;791-1390&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit4&quot; id=&quot;отношение_один_ко_многим&quot;&gt;Отношение «один ко многим»&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
&lt;a href=&quot;http://178.140.10.58:8080/lib/exe/detail.php?id=php%3Alaravel%3Arelations&amp;amp;media=php:laravel:one-to-many.png&quot; class=&quot;media&quot; title=&quot;php:laravel:one-to-many.png&quot;&gt;&lt;img src=&quot;http://178.140.10.58:8080/lib/exe/fetch.php?w=600&amp;amp;tok=1c03ab&amp;amp;media=php:laravel:one-to-many.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; width=&quot;600&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;pre class=&quot;code php&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;&amp;lt;?php&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;namespace&lt;/span&gt; App\Models&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;use&lt;/span&gt; Illuminate\Database\Eloquent\Model&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; Tenant &lt;span class=&quot;kw2&quot;&gt;extends&lt;/span&gt; Model
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;co4&quot;&gt;/**
    * Get the rents of a Tenant
    */&lt;/span&gt;
    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; rent&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; 
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;hasMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Rent&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;co1&quot;&gt;//return $this-&amp;gt;hasMany(Rent::class, &amp;quot;foreign_key&amp;quot;);&lt;/span&gt;
        &lt;span class=&quot;co1&quot;&gt;//return $this-&amp;gt;hasMany(Rent::class, &amp;quot;foreign_key&amp;quot;, &amp;quot;local_key&amp;quot;);&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;re0&quot;&gt;$rents&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; Tenant&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;rent&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st_h&quot;&gt;&#039;payment&#039;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st_h&quot;&gt;&#039;&amp;gt;&#039;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;500&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;code php&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;&amp;lt;?php&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;namespace&lt;/span&gt; App\Models&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;use&lt;/span&gt; Illuminate\Database\Eloquent\Model&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; Rent &lt;span class=&quot;kw2&quot;&gt;extends&lt;/span&gt; Model
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;co4&quot;&gt;/**
    * Return the tenant for the rent
    */&lt;/span&gt;
    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; tenant&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; 
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;belongsTo&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Tenant&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;re0&quot;&gt;$tenant&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; Rent&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;tenant&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;\u041e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u00ab\u043e\u0434\u0438\u043d \u043a\u043e \u043c\u043d\u043e\u0433\u0438\u043c\u00bb&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435_\u043e\u0434\u0438\u043d_\u043a\u043e_\u043c\u043d\u043e\u0433\u0438\u043c&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:2,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;1391-2247&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit5&quot; id=&quot;имеет_отношение_один_из_многих&quot;&gt;Имеет отношение «один из многих»&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;
&lt;pre class=&quot;code php&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; latestRent&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;hasOne&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Rent&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;latestOfMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; oldestRent&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;hasOne&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Rent&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;oldestOfMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;hasOne&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Rent&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;ofMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st_h&quot;&gt;&#039;price&#039;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st_h&quot;&gt;&#039;min&#039;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;\u0418\u043c\u0435\u0435\u0442 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u00ab\u043e\u0434\u0438\u043d \u0438\u0437 \u043c\u043d\u043e\u0433\u0438\u0445\u00bb&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;\u0438\u043c\u0435\u0435\u0442_\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435_\u043e\u0434\u0438\u043d_\u0438\u0437_\u043c\u043d\u043e\u0433\u0438\u0445&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:4,&amp;quot;secid&amp;quot;:5,&amp;quot;range&amp;quot;:&amp;quot;2248-2579&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit6&quot; id=&quot;отношения_hasonethrough_и_hasmanythrough&quot;&gt;Отношения HasOneThrough и HasManyThrough&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
&lt;a href=&quot;http://178.140.10.58:8080/lib/exe/detail.php?id=php%3Alaravel%3Arelations&amp;amp;media=php:laravel:has-one-through.png&quot; class=&quot;media&quot; title=&quot;php:laravel:has-one-through.png&quot;&gt;&lt;img src=&quot;http://178.140.10.58:8080/lib/exe/fetch.php?w=600&amp;amp;tok=3c95b6&amp;amp;media=php:laravel:has-one-through.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; width=&quot;600&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;rent
    id - integer
    name - string
    value - double

tenants
    id - integer
    name - string
    rent_id - integer

landlord
    id - integer
    name - string
    tenant_id - integer&lt;/pre&gt;
&lt;pre class=&quot;code php&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;&amp;lt;?php&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;namespace&lt;/span&gt; App\Models&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;use&lt;/span&gt; Illuminate\Database\Eloquent\Model&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; Rent &lt;span class=&quot;kw2&quot;&gt;extends&lt;/span&gt; Model
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;co4&quot;&gt;/**
    * Return the rents&#039; landlord
    */&lt;/span&gt;
    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; rentLandlord&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; 
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;hasOneThrough&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Landlord&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; Tenant&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;code php&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;&amp;lt;?php&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;namespace&lt;/span&gt; App\Models&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;use&lt;/span&gt; Illuminate\Database\Eloquent\Model&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; Tenant &lt;span class=&quot;kw2&quot;&gt;extends&lt;/span&gt; Model
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;co4&quot;&gt;/**
    * Get the rents of a Tenant
    */&lt;/span&gt;
    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; rent&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; 
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;hasMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Rent&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;code php&quot;&gt;&amp;nbsp;&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;\u041e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f HasOneThrough \u0438 HasManyThrough&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f_hasonethrough_\u0438_hasmanythrough&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:5,&amp;quot;secid&amp;quot;:6,&amp;quot;range&amp;quot;:&amp;quot;2580-3457&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit7&quot; id=&quot;аналогично_отношение_has_many_through&quot;&gt;Аналогично, отношение «Has Many Through»&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
&lt;a href=&quot;http://178.140.10.58:8080/lib/exe/detail.php?id=php%3Alaravel%3Arelations&amp;amp;media=php:laravel:has-many-through.png&quot; class=&quot;media&quot; title=&quot;php:laravel:has-many-through.png&quot;&gt;&lt;img src=&quot;http://178.140.10.58:8080/lib/exe/fetch.php?w=600&amp;amp;tok=48f479&amp;amp;media=php:laravel:has-many-through.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; width=&quot;600&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;country
    id - integer
    name - string

user
    id - integer
    country_id - integer
    name - string

games
    id - integer
    user_id - integer
    title - string
&lt;/pre&gt;
&lt;pre class=&quot;code php&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;&amp;lt;?php&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;namespace&lt;/span&gt; App\Models&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;use&lt;/span&gt; Illuminate\Database\Eloquent\Model&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; Country &lt;span class=&quot;kw2&quot;&gt;extends&lt;/span&gt; Model
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw2&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$fillable&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;st_h&quot;&gt;&#039;name&#039;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; users&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;hasMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;User&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; games&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;hasManyThrough&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Games&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; User&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;code php&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;&amp;lt;?php&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;namespace&lt;/span&gt; App\Models&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;use&lt;/span&gt; Illuminate\Database\Eloquent\Model&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; User &lt;span class=&quot;kw2&quot;&gt;extends&lt;/span&gt; Model
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw2&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$fillable&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;article_id&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st_h&quot;&gt;&#039;name&#039;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; country&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;belongsTo&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Country&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; posts&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;hasMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Post&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;code php&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;&amp;lt;?php&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;namespace&lt;/span&gt; App\Models&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;use&lt;/span&gt; Illuminate\Database\Eloquent\Model&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; Game &lt;span class=&quot;kw2&quot;&gt;extends&lt;/span&gt; Model
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw2&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$fillable&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;st_h&quot;&gt;&#039;user_id&#039;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st_h&quot;&gt;&#039;title&#039;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; user&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;belongsTo&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;User&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;code php&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;&amp;lt;?php&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;re0&quot;&gt;$country&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; Country&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;159&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// Retrieve all games for the country&lt;/span&gt;
&lt;span class=&quot;re0&quot;&gt;$games&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$country&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;games&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u00abHas Many Through\u00bb&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;\u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e_\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435_has_many_through&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:9,&amp;quot;secid&amp;quot;:7,&amp;quot;range&amp;quot;:&amp;quot;3458-4848&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit8&quot; id=&quot;отношение_многие_ко_многим&quot;&gt;Отношение «многие ко многим»&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
&lt;a href=&quot;http://178.140.10.58:8080/lib/exe/detail.php?id=php%3Alaravel%3Arelations&amp;amp;media=php:laravel:many-to-many.png&quot; class=&quot;media&quot; title=&quot;php:laravel:many-to-many.png&quot;&gt;&lt;img src=&quot;http://178.140.10.58:8080/lib/exe/fetch.php?w=600&amp;amp;tok=f46b7c&amp;amp;media=php:laravel:many-to-many.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; width=&quot;600&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;employees
    id - integer
    name - string

roles 
    id - integer
    name - string

role_employees
    user_id - integer
    role_id - integer&lt;/pre&gt;
&lt;pre class=&quot;code php&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;&amp;lt;?php&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;namespace&lt;/span&gt; App\Models&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;use&lt;/span&gt; Illuminate\Database\Eloquent\Model&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; Employee &lt;span class=&quot;kw2&quot;&gt;extends&lt;/span&gt; Model
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; roles&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; 
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;gt;&lt;/span&gt;belongsToMany&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Role&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;code php&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;&amp;lt;?php&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;namespace&lt;/span&gt; App\Models&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;use&lt;/span&gt; Illuminate\Database\Eloquent\Model&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; Role &lt;span class=&quot;kw2&quot;&gt;extends&lt;/span&gt; Model
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; employees&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; 
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;belongsToMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Employee&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;belongsToMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Employee&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;withPivot&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;active&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;created_at&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;belongsToMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Employee&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;withTimestamps&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;belongsToMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Employee&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st_h&quot;&gt;&#039;subscription&#039;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;withPivot&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;active&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;created_by&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;belongsToMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Employee&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;wherePivot&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st_h&quot;&gt;&#039;promoted&#039;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;belongsToMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Employee&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;wherePivotIn&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st_h&quot;&gt;&#039;level&#039;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;belongsToMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Employee&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;wherePivotNotIn&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st_h&quot;&gt;&#039;level&#039;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;belongsToMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Employee&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;wherePivotBetween&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st_h&quot;&gt;&#039;posted_at&#039;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;st_h&quot;&gt;&#039;2023-01-01 00:00:00&#039;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st_h&quot;&gt;&#039;2023-01-02 00:00:00&#039;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;belongsToMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Employee&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;wherePivotNull&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st_h&quot;&gt;&#039;expired_at&#039;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;belongsToMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Employee&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;wherePivotNotNull&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st_h&quot;&gt;&#039;posted_at&#039;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
          &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;belongsToMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Employee&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st_h&quot;&gt;&#039;promoted&#039;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
            &lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;orderByPivot&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st_h&quot;&gt;&#039;hired_at&#039;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st_h&quot;&gt;&#039;desc&#039;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;belongsToMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Employee&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
                            &lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;using&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;RoleEmployees&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
                            &lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;withPivot&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;
                                &lt;span class=&quot;st_h&quot;&gt;&#039;user_id&#039;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
                                &lt;span class=&quot;st_h&quot;&gt;&#039;role_id&#039;&lt;/span&gt;
                            &lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;code php&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; RoleEmployees 
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;code php&quot;&gt;&lt;span class=&quot;re0&quot;&gt;$employee&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; Employee&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;re0&quot;&gt;$employee&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;roles&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;re0&quot;&gt;$role&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;// });&lt;/span&gt;
&lt;span class=&quot;re0&quot;&gt;$employee&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; Employee&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;roles&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;orderBy&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st_h&quot;&gt;&#039;name&#039;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st_h&quot;&gt;&#039;name&#039;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st_h&quot;&gt;&#039;admin&#039;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;\u041e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u00ab\u043c\u043d\u043e\u0433\u0438\u0435 \u043a\u043e \u043c\u043d\u043e\u0433\u0438\u043c\u00bb&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435_\u043c\u043d\u043e\u0433\u0438\u0435_\u043a\u043e_\u043c\u043d\u043e\u0433\u0438\u043c&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:14,&amp;quot;secid&amp;quot;:8,&amp;quot;range&amp;quot;:&amp;quot;4849-7157&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit9&quot; id=&quot;полиморфный_один_к_одному&quot;&gt;Полиморфный Один к одному&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
&lt;a href=&quot;http://178.140.10.58:8080/lib/exe/detail.php?id=php%3Alaravel%3Arelations&amp;amp;media=php:laravel:one-to-one-polymorphic.png&quot; class=&quot;media&quot; title=&quot;php:laravel:one-to-one-polymorphic.png&quot;&gt;&lt;img src=&quot;http://178.140.10.58:8080/lib/exe/fetch.php?w=600&amp;amp;tok=9acad1&amp;amp;media=php:laravel:one-to-one-polymorphic.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; width=&quot;600&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;tenants
    id – integer
    name – string

landlords
    id – integer
    name – string

waterbills
    id – integer
    amount – double
    waterbillable_id
    waterbillable_type&lt;/pre&gt;
&lt;pre class=&quot;code php&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;&amp;lt;?php&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;namespace&lt;/span&gt; App\Models&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;use&lt;/span&gt; Illuminate\Database\Eloquent\Model&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; WaterBill &lt;span class=&quot;kw2&quot;&gt;extends&lt;/span&gt; Model
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; billable&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;morphTo&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; Tenant &lt;span class=&quot;kw2&quot;&gt;extends&lt;/span&gt; Model
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; waterBill&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;    
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;morphOne&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;WaterBill&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st_h&quot;&gt;&#039;billable&#039;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; Landlord &lt;span class=&quot;kw2&quot;&gt;extends&lt;/span&gt; Model
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; waterBill&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;    
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;morphOne&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;WaterBill&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st_h&quot;&gt;&#039;billable&#039;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;code php&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;&amp;lt;?php&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;re0&quot;&gt;$tenant&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; Tenant&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;waterBill&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;re0&quot;&gt;$landlord&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; Landlord&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;waterBill&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;\u041f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u043d\u044b\u0439 \u041e\u0434\u0438\u043d \u043a \u043e\u0434\u043d\u043e\u043c\u0443&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;\u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u043d\u044b\u0439_\u043e\u0434\u0438\u043d_\u043a_\u043e\u0434\u043d\u043e\u043c\u0443&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:19,&amp;quot;secid&amp;quot;:9,&amp;quot;range&amp;quot;:&amp;quot;7158-8075&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit10&quot; id=&quot;полиморфный_один_ко_многим&quot;&gt;Полиморфный Один Ко Многим&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
&lt;a href=&quot;http://178.140.10.58:8080/lib/exe/detail.php?id=php%3Alaravel%3Arelations&amp;amp;media=php:laravel:one-to-many-polymorphic.png&quot; class=&quot;media&quot; title=&quot;php:laravel:one-to-many-polymorphic.png&quot;&gt;&lt;img src=&quot;http://178.140.10.58:8080/lib/exe/fetch.php?w=600&amp;amp;tok=dc5a47&amp;amp;media=php:laravel:one-to-many-polymorphic.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; width=&quot;600&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;posts 
    id – integer
    title – string
    body – text

videos
    id – integer
    title – string
    url – string

polls
    id – integer
    title – string

comments 
    id – integer
    body – text
    commentable_id – integer
    commentable_type – string&lt;/pre&gt;
&lt;pre class=&quot;code php&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;&amp;lt;?php&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;namespace&lt;/span&gt; App\Models&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;use&lt;/span&gt; Illuminate\Database\Eloquent\Model&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; Comment &lt;span class=&quot;kw2&quot;&gt;extends&lt;/span&gt; Model 
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; commentable&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;morphTo&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; Poll &lt;span class=&quot;kw2&quot;&gt;extends&lt;/span&gt; Model
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; comments&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;morphMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Comment&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st_h&quot;&gt;&#039;commentable&#039;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; Live &lt;span class=&quot;kw2&quot;&gt;extends&lt;/span&gt; Model
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; comments&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;morphMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Comments&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st_h&quot;&gt;&#039;commentable&#039;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;code php&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;&amp;lt;?php&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;use&lt;/span&gt; App\Models\Live&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;use&lt;/span&gt; App\Models\Comment&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;re0&quot;&gt;$live&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; Live&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw1&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;re0&quot;&gt;$live&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;comments&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$comment&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// OR&lt;/span&gt;
&amp;nbsp;
Live&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;comments&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/each&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;each&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;re0&quot;&gt;$comment&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;// });&lt;/span&gt;
Live&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;comments&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;re0&quot;&gt;$comment&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;// });&lt;/span&gt;
Live&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;comments&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;re0&quot;&gt;$comment&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;// });&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;re0&quot;&gt;$comment&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; Comment&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;re0&quot;&gt;$commentable&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$comment&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;commentable&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;\u041f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u043d\u044b\u0439 \u041e\u0434\u0438\u043d \u041a\u043e \u041c\u043d\u043e\u0433\u0438\u043c&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;\u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u043d\u044b\u0439_\u043e\u0434\u0438\u043d_\u043a\u043e_\u043c\u043d\u043e\u0433\u0438\u043c&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:22,&amp;quot;secid&amp;quot;:10,&amp;quot;range&amp;quot;:&amp;quot;8076-9373&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit11&quot; id=&quot;полиморфный_один_из_многих&quot;&gt;Полиморфный Один из Многих&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;\u041f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u043d\u044b\u0439 \u041e\u0434\u0438\u043d \u0438\u0437 \u041c\u043d\u043e\u0433\u0438\u0445&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;\u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u043d\u044b\u0439_\u043e\u0434\u0438\u043d_\u0438\u0437_\u043c\u043d\u043e\u0433\u0438\u0445&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:25,&amp;quot;secid&amp;quot;:11,&amp;quot;range&amp;quot;:&amp;quot;9374-9438&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit12&quot; id=&quot;полиморфный_многие-к-многим&quot;&gt;Полиморфный Многие-К-Многим&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
&lt;a href=&quot;http://178.140.10.58:8080/lib/exe/detail.php?id=php%3Alaravel%3Arelations&amp;amp;media=php:laravel:many-to-many-polymorphic.png&quot; class=&quot;media&quot; title=&quot;php:laravel:many-to-many-polymorphic.png&quot;&gt;&lt;img src=&quot;http://178.140.10.58:8080/lib/exe/fetch.php?w=600&amp;amp;tok=523d33&amp;amp;media=php:laravel:many-to-many-polymorphic.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; width=&quot;600&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;videos
    id – integer
    description – string

stories 
    id – integer
    description – string

taggables 
    tag_id – integer
    taggable_id – integer
    taggable_type – string&lt;/pre&gt;
&lt;pre class=&quot;code php&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;&amp;lt;?php&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;namespace&lt;/span&gt; App\Models&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;use&lt;/span&gt; Illuminate\Database\Eloquent\Model&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; Video &lt;span class=&quot;kw2&quot;&gt;extends&lt;/span&gt; Model
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; tags&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;morphToMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Tag&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st_h&quot;&gt;&#039;taggable&#039;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;code php&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;&amp;lt;?php&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;namespace&lt;/span&gt; App\Models&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;use&lt;/span&gt; Illuminate\Database\Eloquent\Model&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; Tag &lt;span class=&quot;kw2&quot;&gt;extends&lt;/span&gt; Model
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; stories&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;morphedByMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Story&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st_h&quot;&gt;&#039;taggable&#039;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    &lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;function&lt;/span&gt; videos&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;morphedByMany&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Video&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st_h&quot;&gt;&#039;taggable&#039;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt; 
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;code php&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;use&lt;/span&gt; App\Model\Tag&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;re0&quot;&gt;$tag&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; Tag&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;re0&quot;&gt;$posts&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$tag&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;stories&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;re0&quot;&gt;$videos&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;re0&quot;&gt;$tag&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;me1&quot;&gt;stories&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;\u041f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u043d\u044b\u0439 \u041c\u043d\u043e\u0433\u0438\u0435-\u041a-\u041c\u043d\u043e\u0433\u0438\u043c&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;\u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u043d\u044b\u0439_\u043c\u043d\u043e\u0433\u0438\u0435-\u043a-\u043c\u043d\u043e\u0433\u0438\u043c&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:25,&amp;quot;secid&amp;quot;:12,&amp;quot;range&amp;quot;:&amp;quot;9439-&amp;quot;} --&gt;</description>
    </item>
</rdf:RDF>
