1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-26 09:46:49 +00:00
pixelfed/app/Http/Controllers/LikeController.php

42 lines
975 B
PHP
Raw Normal View History

<?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};
use App\Jobs\LikePipeline\LikePipeline;
class LikeController extends Controller
{
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',
]);
$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();
LikePipeline::dispatch($like);
2018-05-26 22:59:31 +00:00
return redirect($status->url());
}
}