73
app/Http/Controllers/Api/LikeController.php
Normal file
73
app/Http/Controllers/Api/LikeController.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Ejaculation;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Like;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class LikeController extends Controller
|
||||
{
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'id' => 'required|integer|exists:ejaculations'
|
||||
]);
|
||||
|
||||
$keys = [
|
||||
'user_id' => Auth::id(),
|
||||
'ejaculation_id' => $request->input('id')
|
||||
];
|
||||
|
||||
$like = Like::query()->where($keys)->first();
|
||||
if ($like) {
|
||||
$data = [
|
||||
'errors' => [
|
||||
['message' => 'このチェックインはすでにいいね済です。']
|
||||
],
|
||||
'ejaculation' => $like->ejaculation
|
||||
];
|
||||
|
||||
return response()->json($data, 409);
|
||||
}
|
||||
|
||||
$like = Like::create($keys);
|
||||
|
||||
return [
|
||||
'ejaculation' => $like->ejaculation
|
||||
];
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
Validator::make(compact('id'), [
|
||||
'id' => 'required|integer'
|
||||
])->validate();
|
||||
|
||||
$like = Like::query()->where([
|
||||
'user_id' => Auth::id(),
|
||||
'ejaculation_id' => $id
|
||||
])->first();
|
||||
if ($like === null) {
|
||||
$ejaculation = Ejaculation::find($id);
|
||||
|
||||
$data = [
|
||||
'errors' => [
|
||||
['message' => 'このチェックインはいいねされていません。']
|
||||
],
|
||||
'ejaculation' => $ejaculation
|
||||
];
|
||||
|
||||
return response()->json($data, 404);
|
||||
}
|
||||
|
||||
$like->delete();
|
||||
|
||||
return [
|
||||
'ejaculation' => $like->ejaculation
|
||||
];
|
||||
}
|
||||
}
|
@@ -78,7 +78,9 @@ class EjaculationController extends Controller
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$ejaculation = Ejaculation::findOrFail($id);
|
||||
$ejaculation = Ejaculation::where('id', $id)
|
||||
->withLikes()
|
||||
->firstOrFail();
|
||||
$user = User::findOrFail($ejaculation->user_id);
|
||||
|
||||
// 1つ前のチェックインからの経過時間を求める
|
||||
|
@@ -69,6 +69,7 @@ SQL
|
||||
->orderBy('ejaculations.ejaculated_date', 'desc')
|
||||
->select('ejaculations.*')
|
||||
->with('user', 'tags')
|
||||
->withLikes()
|
||||
->take(10)
|
||||
->get();
|
||||
|
||||
|
@@ -28,6 +28,7 @@ class SearchController extends Controller
|
||||
->where('is_private', false)
|
||||
->orderBy('ejaculated_date', 'desc')
|
||||
->with(['user', 'tags'])
|
||||
->withLikes()
|
||||
->paginate(20)
|
||||
->appends($inputs);
|
||||
|
||||
|
@@ -46,11 +46,12 @@ class SettingController extends Controller
|
||||
|
||||
public function updatePrivacy(Request $request)
|
||||
{
|
||||
$inputs = $request->all(['is_protected', 'accept_analytics']);
|
||||
$inputs = $request->all(['is_protected', 'accept_analytics', 'private_likes']);
|
||||
|
||||
$user = Auth::user();
|
||||
$user->is_protected = $inputs['is_protected'] ?? false;
|
||||
$user->accept_analytics = $inputs['accept_analytics'] ?? false;
|
||||
$user->private_likes = $inputs['private_likes'] ?? false;
|
||||
$user->save();
|
||||
|
||||
return redirect()->route('setting.privacy')->with('status', 'プライバシー設定を更新しました。');
|
||||
|
@@ -16,6 +16,7 @@ class TimelineController extends Controller
|
||||
->orderBy('ejaculations.ejaculated_date', 'desc')
|
||||
->select('ejaculations.*')
|
||||
->with('user', 'tags')
|
||||
->withLikes()
|
||||
->paginate(21);
|
||||
|
||||
return view('timeline.public')->with(compact('ejaculations'));
|
||||
|
@@ -41,6 +41,7 @@ SQL
|
||||
}
|
||||
$ejaculations = $query->orderBy('ejaculated_date', 'desc')
|
||||
->with('tags')
|
||||
->withLikes()
|
||||
->paginate(20);
|
||||
|
||||
// よく使っているタグ
|
||||
@@ -176,4 +177,19 @@ SQL
|
||||
|
||||
return view('user.profile')->with(compact('user', 'ejaculations'));
|
||||
}
|
||||
|
||||
public function likes($name)
|
||||
{
|
||||
$user = User::where('name', $name)->first();
|
||||
if (empty($user)) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$likes = $user->likes()
|
||||
->orderBy('created_at', 'desc')
|
||||
->with('ejaculation.user', 'ejaculation.tags')
|
||||
->paginate(20);
|
||||
|
||||
return view('user.likes')->with(compact('user', 'likes'));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user