2018-04-17 01:35:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
2018-05-26 22:59:31 +00:00
|
|
|
use Auth, Hashids;
|
|
|
|
use App\{Like, Profile, Status, User};
|
2018-05-27 02:26:44 +00:00
|
|
|
use App\Jobs\LikePipeline\LikePipeline;
|
2018-04-17 01:35:01 +00:00
|
|
|
|
|
|
|
class LikeController extends Controller
|
|
|
|
{
|
2018-05-27 02:26:44 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware('auth');
|
|
|
|
}
|
|
|
|
|
2018-05-26 22:59:31 +00:00
|
|
|
public function store(Request $request)
|
|
|
|
{
|
|
|
|
$this->validate($request, [
|
|
|
|
'item' => 'required|integer',
|
|
|
|
]);
|
|
|
|
|
2018-05-27 02:26:44 +00:00
|
|
|
$profile = Auth::user()->profile;
|
|
|
|
$status = Status::findOrFail($request->input('item'));
|
2018-05-26 22:59:31 +00:00
|
|
|
|
|
|
|
if($status->likes()->whereProfileId($profile->id)->count() !== 0) {
|
|
|
|
$like = Like::whereProfileId($profile->id)->whereStatusId($status->id)->firstOrFail();
|
|
|
|
$like->delete();
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
|
|
|
$like = new Like;
|
|
|
|
$like->profile_id = $profile->id;
|
|
|
|
$like->status_id = $status->id;
|
|
|
|
$like->save();
|
|
|
|
|
2018-05-27 02:26:44 +00:00
|
|
|
LikePipeline::dispatch($like);
|
|
|
|
|
2018-05-26 22:59:31 +00:00
|
|
|
return redirect($status->url());
|
|
|
|
}
|
2018-04-17 01:35:01 +00:00
|
|
|
}
|