PHP code example of kalshah / dynamic-relations-includes

1. Go to this page and download the library: Download kalshah/dynamic-relations-includes 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/ */

    

kalshah / dynamic-relations-includes example snippets


namespace App;

use Illuminate\Database\Eloquent\Model;
use Kalshah\DynamicRelationsInclude\IncludeRelations;

class Post extends Model
{
    use IncludeRelations;

    protected $loadableRelations = ['comments'];

    public function comments()
    {
        return $this->hasMany(Comment::class);
    }
}

namespace App;

use Illuminate\Database\Eloquent\Model;
use Kalshah\DynamicRelationsInclude\IncludeRelations;

class Post extends Model
{
    use IncludeRelations;

    protected $loadableRelationsCount = ['comments'];

    public function comments()
    {
        return $this->hasMany(Comment::class);
    }
}

  protected $loadableRelations = ['comments', 'comments.creator'];
  

    namespace App;

    use Illuminate\Database\Eloquent\Model;
    use Kalshah\DynamicRelationsInclude\IncludeRelations;

    class Profile extends Model
    {
        use IncludeRelations;

        protected $loadableRelationsCount = ['socialMediaAccounts'];

        public function socialMediaAccounts()
        {
            return $this->hasMany(socialMediaAccount::class);
        }
    }