Skip to content

Instantly share code, notes, and snippets.

@segun6060
Created March 13, 2017 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save segun6060/e1c7f010bda166addcb7cc740085921e to your computer and use it in GitHub Desktop.
Save segun6060/e1c7f010bda166addcb7cc740085921e to your computer and use it in GitHub Desktop.
public function up()
{
Schema::create('friend_users', function (Blueprint $table) {
$table->integer('user_id')->unsigned();
$table->integer('friend_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('friend_id')->references('id')->on('users');
$table->primary(['user_id', 'friend_id']);
});
}
@foreach(Auth::user() as $singleUser)
<li>
<ul>
@foreach($singleUser->friends as $friend)
<li>$friend->name</li>
@endforeach
</ul>
</li>
@endforeach
public function friends()
{
return $this->belongsToMany('App\User', 'friend_users', 'user_id', 'friend_id');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment