PHP code example of aw-studio / laravel-dynamic-relations

1. Go to this page and download the library: Download aw-studio/laravel-dynamic-relations library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aw-studio / laravel-dynamic-relations example snippets


composer 

php artisan vendor:publish --tag="dynamic-relations:migraitons"

use Illuminate\Database\Eloquent\Model;
use AwStudio\DynamicRelations\HasDynamicRelations;

class Page extends Model
{
    use HasDynamicRelations;
}

$page = Page::create();

$page->attach('article', $article)

dd($page->article); // Is the attached article

$page->detach('article', $article);

$page = Page::create();

$page->attach('article', collect([$article]));

dd($page->article); // A collection containing the attached article.