1
0
Fork 0
pixelfed/app/Http/Controllers/FollowerController.php

43 lines
1.0 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers;
2018-05-30 02:59:10 +00:00
use Auth;
use App\{Follower, Profile};
use Illuminate\Http\Request;
2018-05-30 02:59:10 +00:00
use App\Jobs\FollowPipeline\FollowPipeline;
class FollowerController extends Controller
{
2018-05-30 02:59:10 +00:00
public function __construct()
{
$this->middleware('auth');
}
public function store(Request $request)
{
$this->validate($request, [
'item' => 'required|integer',
]);
$user = Auth::user()->profile;
$target = Profile::where('id', '!=', $user->id)->findOrFail($request->input('item'));
$isFollowing = Follower::whereProfileId($user->id)->whereFollowingId($target->id)->count();
if($isFollowing == 0) {
$follower = new Follower;
$follower->profile_id = $user->id;
$follower->following_id = $target->id;
$follower->save();
FollowPipeline::dispatch($follower);
} else {
$follower = Follower::whereProfileId($user->id)->whereFollowingId($target->id)->firstOrFail();
$follower->delete();
}
return redirect()->back();
}
}