Skip to content

Commit

Permalink
follow / follower first implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-butti committed Jan 18, 2016
1 parent 7cb3c44 commit 6cc9c77
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@
Route::delete('/clip/{clip}', 'ClipController@destroy');
Route::delete('/api/clip/save', 'ClipController@save');

Route::get('/user/follow/{user}', 'UserController@follow');

});
15 changes: 15 additions & 0 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,19 @@ public function clips()
{
return $this->hasMany(Clip::class);
}



//get all the followers of the current user
public function Followers()
{
return $this->belongsToMany('App\User', 'user_follower_list', 'user_id', 'follower_id' );
}

//get all the Users this user is following
public function FollowingList()
{
return $this->belongsToMany('App\User', 'user_follower_list', 'follower_id', 'user_id' );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddFollowToUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('user_follower_list', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');

$table->integer('follower_id')->unsigned();
$table->foreign('follower_id')->references('id')->on('users')->onDelete('cascade');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('user_follower_list');
}
}
8 changes: 5 additions & 3 deletions resources/views/clips/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
<div class="photo-profile"><img src="/img/profile/{{ Auth::user()->photo_profile }}"></div>
</div>
<div>{{ Auth::user()->name }}</div>
<div>I have {{ Auth::user()->Followers()->count() }} followers</div>
<div>I follow {{ Auth::user()->FollowingList()->count() }} people</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -76,7 +78,7 @@
<!-- Delete Button -->
<div class="options-clip">
<form action="/clip/{{ $clip->id }}" method="POST">
{{ csrf_field() }}
{{ csrf_field() }}
{{ method_field('DELETE') }}
<ul>
<li class="dropdown">
Expand All @@ -92,7 +94,7 @@
</form>
</div>


</div>
</li>
@endforeach
Expand All @@ -103,7 +105,7 @@
<div class="col-pad">
<div pin-to=".clips-container">
<div class="user elementCards">

</div>
</div>
</div>
Expand Down

0 comments on commit 6cc9c77

Please sign in to comment.