PHP code example of fs-ap / laravel-relationship-test

1. Go to this page and download the library: Download fs-ap/laravel-relationship-test 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/ */

    

fs-ap / laravel-relationship-test example snippets




use Fs\Relationship;

	class AuthorModelTest extends PHPUnit_Framework_TestCase {
    
        /**
         * Check if the class in first param has a method that defines relation of type Relationship::HAS_MANY
         * and the second class has a relation of type Relationship::BELONGS_TO
         */
        public function testAuthorCanHaveManyComments()
        {
            Relationship::check(Author::class, Relationship::HAS_MANY, Comment::class));
        }
    }



	class Author extends Illuminate\Database\Eloquent\Model {
    
        /**
		* @return Illuminate\Database\Eloquent\Relations\HasMany
        */
        public function comments() { return \$this->hasMany(Comment::class); }
    }



	class Comment extends Illuminate\Database\Eloquent\Model {

        /**
        * @return Illuminate\Database\Eloquent\Relations\BelongsTo
        */
        public function author() { return \$this->belongsTo(Author::class); }
    }



Relationship::check(Author::class, Relationship::HAS_MANY, Comment::class, true);