2016-07-11 7 views
0

Laravel 5.2にthis solutionを実装しようとしました。 すべてのインストール手順を実行しましたが、動作させることができません。たとえば、$user->getFriends();を使用したい場合は、ビューから直接使用するか、コンストラクタからのみ使用できますか? 私はUser.php上でモデルをセットアップする必要がありますか、Friend.phpでそれを行うことができますか?Laravel 5.2、友情モデル、ユーザーモデルで正しく追加する方法は?

答えて

1

UserモデルにFriendableの特性を追加したいとします。

use Hootlex\Friendships\Traits\Friendable; 
class User extends Model 
{ 
    use Friendable; 
    ... 
} 

あなたはすべてのものをインストールし、データベースを移行した場合次に、あなたは以下のような友情にアクセスすることができます。

$user = new User::find(1); 
$recipient = new User::find(2); 
// both `$user` and `$recipient` are instances of your `User` model 
// no `Friend` model needed. 


$user->befriend($recipient); 
// now `$user` has just friended `$recipient` 
// you should be able to access all the methods provided by the trait. 
+0

はあなたにMr.Swatkinsをありがとう! – Alex

関連する問題