-
-
Save DavidStrada/c887085425ff78f6be50e8a30083a278 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
use Illuminate\Database\Eloquent\Model; | |
class Article extends Model | |
{ | |
protected $fillable = ['name', 'content']; | |
public function laws() | |
{ | |
return $this->belongsTo(Law::class); | |
} | |
public function references() | |
{ | |
return $this->belongsToMany(Article::class, 'article_reference', 'article_id', 'reference_id'); | |
} | |
public function referenced() | |
{ | |
return $this->belongsToMany(Article::class, 'article_reference', 'reference_id', 'article_id'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Schema::create('article_reference', function(BluePrint $table){ | |
$table->unsignedInteger('article_id'); | |
$table->unsignedInteger('reference_id'); | |
$table->foreign('article_id')->references('id')->on('articles'); | |
$table->foreign('reference_id')->references('id')->on('articles'); | |
$table->primary(['article_id', 'reference_id']); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment