Created
March 13, 2017 16:31
-
-
Save segun6060/e1c7f010bda166addcb7cc740085921e to your computer and use it in GitHub Desktop.
This file contains 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
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']); | |
}); | |
} |
This file contains 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
@foreach(Auth::user() as $singleUser) | |
<li> | |
<ul> | |
@foreach($singleUser->friends as $friend) | |
<li>$friend->name</li> | |
@endforeach | |
</ul> | |
</li> | |
@endforeach |
This file contains 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
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