From 34b7cd6c89a809d921a4e50bc01d444f87909159 Mon Sep 17 00:00:00 2001 From: shibafu Date: Fri, 5 Apr 2019 23:07:43 +0900 Subject: [PATCH 01/19] =?UTF-8?q?Like=20API=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/LikeController.php | 71 +++++++++++++++++++ app/Http/Kernel.php | 5 ++ app/Like.php | 20 ++++++ .../2019_03_26_224641_create_likes_table.php | 37 ++++++++++ routes/api.php | 5 ++ 5 files changed, 138 insertions(+) create mode 100644 app/Http/Controllers/Api/LikeController.php create mode 100644 app/Like.php create mode 100644 database/migrations/2019_03_26_224641_create_likes_table.php diff --git a/app/Http/Controllers/Api/LikeController.php b/app/Http/Controllers/Api/LikeController.php new file mode 100644 index 0000000..09bf161 --- /dev/null +++ b/app/Http/Controllers/Api/LikeController.php @@ -0,0 +1,71 @@ +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 + ]; + } +} diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 95714cf..dfa1743 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -38,7 +38,12 @@ class Kernel extends HttpKernel \App\Http\Middleware\NormalizeLineEnding::class, ], + // 現時点では内部APIしかないので、認証の手間を省くためにステートフルにしている。 'api' => [ + \App\Http\Middleware\EncryptCookies::class, + \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, + \Illuminate\Session\Middleware\StartSession::class, + \App\Http\Middleware\VerifyCsrfToken::class, 'throttle:60,1', 'bindings', ], diff --git a/app/Like.php b/app/Like.php new file mode 100644 index 0000000..f4a6061 --- /dev/null +++ b/app/Like.php @@ -0,0 +1,20 @@ +belongsTo(User::class); + } + + public function ejaculation() + { + return $this->belongsTo(Ejaculation::class)->withLikes(); + } +} diff --git a/database/migrations/2019_03_26_224641_create_likes_table.php b/database/migrations/2019_03_26_224641_create_likes_table.php new file mode 100644 index 0000000..08a59c8 --- /dev/null +++ b/database/migrations/2019_03_26_224641_create_likes_table.php @@ -0,0 +1,37 @@ +increments('id'); + $table->integer('user_id')->index(); + $table->integer('ejaculation_id')->index(); + $table->timestamps(); + + $table->unique(['user_id', 'ejaculation_id']); + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + $table->foreign('ejaculation_id')->references('id')->on('ejaculations')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('likes'); + } +} diff --git a/routes/api.php b/routes/api.php index 39be95a..2461cdb 100644 --- a/routes/api.php +++ b/routes/api.php @@ -16,3 +16,8 @@ //}); Route::get('/checkin/card', 'Api\\CardController@show'); + +Route::middleware('auth')->group(function () { + Route::post('/likes', 'Api\\LikeController@store'); + Route::delete('/likes/{id}', 'Api\\LikeController@destroy'); +}); \ No newline at end of file From 225d0854efe92dce1a16e7966150dc880af56963 Mon Sep 17 00:00:00 2001 From: shibafu Date: Fri, 5 Apr 2019 23:10:26 +0900 Subject: [PATCH 02/19] =?UTF-8?q?=E3=81=84=E3=81=84=E3=81=AD=E3=83=9C?= =?UTF-8?q?=E3=82=BF=E3=83=B3=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Ejaculation.php | 23 +++++++ .../Controllers/EjaculationController.php | 4 +- app/Http/Controllers/HomeController.php | 1 + app/Http/Controllers/SearchController.php | 1 + app/Http/Controllers/TimelineController.php | 1 + app/Http/Controllers/UserController.php | 1 + app/User.php | 5 ++ resources/assets/js/app.js | 65 +++++++++++++++++++ resources/assets/sass/app.scss | 10 ++- resources/assets/sass/tissue.css | 4 -- .../views/components/ejaculation.blade.php | 35 ++++++++++ resources/views/ejaculation/show.blade.php | 7 +- resources/views/home.blade.php | 36 +--------- resources/views/search/index.blade.php | 39 +---------- resources/views/timeline/public.blade.php | 39 +---------- resources/views/user/profile.blade.php | 7 +- 16 files changed, 158 insertions(+), 120 deletions(-) create mode 100644 resources/views/components/ejaculation.blade.php diff --git a/app/Ejaculation.php b/app/Ejaculation.php index 83b3ad2..3794add 100644 --- a/app/Ejaculation.php +++ b/app/Ejaculation.php @@ -2,7 +2,9 @@ namespace App; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\Auth; class Ejaculation extends Model { @@ -34,4 +36,25 @@ class Ejaculation extends Model return $v->name; })->all()); } + + public function likes() + { + return $this->hasMany(Like::class); + } + + public function scopeWithLikes(Builder $query) + { + if (Auth::check()) { + // (ejaculation_id, user_id) でユニークなわけですが、サブクエリ発行させるのとLeft JoinしてNULLかどうかで結果を見るのどっちがいいんでしょうね + return $query->withCount([ + 'likes', + 'likes as is_liked' => function ($query) { + $query->where('user_id', Auth::id()); + } + ]); + } else { + return $query->withCount('likes') + ->addSelect('0 as is_liked'); + } + } } diff --git a/app/Http/Controllers/EjaculationController.php b/app/Http/Controllers/EjaculationController.php index d2292e0..13ef8c4 100644 --- a/app/Http/Controllers/EjaculationController.php +++ b/app/Http/Controllers/EjaculationController.php @@ -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つ前のチェックインからの経過時間を求める diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 95807a5..fb8147f 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -69,6 +69,7 @@ SQL ->orderBy('ejaculations.ejaculated_date', 'desc') ->select('ejaculations.*') ->with('user', 'tags') + ->withLikes() ->take(10) ->get(); diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php index 3fa2725..2ca3801 100644 --- a/app/Http/Controllers/SearchController.php +++ b/app/Http/Controllers/SearchController.php @@ -21,6 +21,7 @@ class SearchController extends Controller ->where('is_private', false) ->orderBy('ejaculated_date', 'desc') ->with(['user', 'tags']) + ->withLikes() ->paginate(20) ->appends($inputs); diff --git a/app/Http/Controllers/TimelineController.php b/app/Http/Controllers/TimelineController.php index a179537..2f05b71 100644 --- a/app/Http/Controllers/TimelineController.php +++ b/app/Http/Controllers/TimelineController.php @@ -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')); diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 1640c78..442dcf9 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -41,6 +41,7 @@ SQL } $ejaculations = $query->orderBy('ejaculated_date', 'desc') ->with('tags') + ->withLikes() ->paginate(20); // よく使っているタグ diff --git a/app/User.php b/app/User.php index 5469e52..3b2b251 100644 --- a/app/User.php +++ b/app/User.php @@ -51,4 +51,9 @@ class User extends Authenticatable { return Auth::check() && $this->id === Auth::user()->id; } + + public function likes() + { + return $this->hasMany(Like::class); + } } diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index 6af9993..bf79d54 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -27,4 +27,69 @@ $(() => { event.preventDefault(); $deleteCheckinModal.modal('show', this); }); + + $(document).on('click', '[data-href]', function (event) { + location.href = $(this).data('href'); + }); + + $(document).on('click', '.like-button', function (event) { + event.preventDefault(); + + const $this = $(this); + const targetId = $this.data('id'); + const isLiked = $this.data('liked'); + + if (isLiked) { + const callback = (data) => { + $this.data('liked', false); + $this.find('.oi-heart').removeClass('text-danger'); + + const count = data.ejaculation ? data.ejaculation.likes_count : 0; + $this.find('.like-count').text(count ? count : ''); + }; + + $.ajax({ + url: '/api/likes/' + encodeURIComponent(targetId), + method: 'delete', + type: 'json' + }) + .then(callback) + .catch(function (xhr) { + if (xhr.status === 404) { + callback(JSON.parse(xhr.responseText)); + return; + } + + console.error(xhr); + alert('いいねを解除できませんでした。'); + }); + } else { + const callback = (data) => { + $this.data('liked', true); + $this.find('.oi-heart').addClass('text-danger'); + + const count = data.ejaculation ? data.ejaculation.likes_count : 0; + $this.find('.like-count').text(count ? count : ''); + }; + + $.ajax({ + url: '/api/likes', + method: 'post', + type: 'json', + data: { + id: targetId + } + }) + .then(callback) + .catch(function (xhr) { + if (xhr.status === 409) { + callback(JSON.parse(xhr.responseText)); + return; + } + + console.error(xhr); + alert('いいねできませんでした。'); + }); + } + }); }); \ No newline at end of file diff --git a/resources/assets/sass/app.scss b/resources/assets/sass/app.scss index e691a70..c3b8f50 100644 --- a/resources/assets/sass/app.scss +++ b/resources/assets/sass/app.scss @@ -12,4 +12,12 @@ $primary: #e53fb1; @import "tissue.css"; // Components -@import "components/link-card"; \ No newline at end of file +@import "components/link-card"; + +.like-button { + text-decoration: none !important; +} + +.like-count:not(:empty) { + padding-left: 0.25rem; +} \ No newline at end of file diff --git a/resources/assets/sass/tissue.css b/resources/assets/sass/tissue.css index 2dd99e2..c8d5f15 100644 --- a/resources/assets/sass/tissue.css +++ b/resources/assets/sass/tissue.css @@ -40,10 +40,6 @@ border-top: none; } -.timeline-action-item { - margin-left: 16px; -} - .tis-global-count-graph { height: 90px; border-bottom: 1px solid rgba(0, 0, 0, .125); diff --git a/resources/views/components/ejaculation.blade.php b/resources/views/components/ejaculation.blade.php new file mode 100644 index 0000000..a1d4a3f --- /dev/null +++ b/resources/views/components/ejaculation.blade.php @@ -0,0 +1,35 @@ + +
+
+ {{ $ejaculation->user->display_name }} + {{ $ejaculation->ejaculated_date->format('Y/m/d H:i') }} +
+
+ + +
+
+ +@if ($ejaculation->tags->isNotEmpty()) +

+ @foreach ($ejaculation->tags as $tag) + {{ $tag->name }} + @endforeach +

+@endif + +@if (!empty($ejaculation->link)) +
+ @component('components.link-card', ['link' => $ejaculation->link]) + @endcomponent +

+ {{ $ejaculation->link }} +

+
+@endif + +@if (!empty($ejaculation->note)) +

+ {!! Formatter::linkify(nl2br(e($ejaculation->note))) !!} +

+@endif \ No newline at end of file diff --git a/resources/views/ejaculation/show.blade.php b/resources/views/ejaculation/show.blade.php index 0f2c78a..69ae3e9 100644 --- a/resources/views/ejaculation/show.blade.php +++ b/resources/views/ejaculation/show.blade.php @@ -33,10 +33,11 @@
{{ $ejaculatedSpan ?? '精通' }} {{ $ejaculation->before_date }}{{ !empty($ejaculation->before_date) ? ' ~ ' : '' }}{{ $ejaculation->ejaculated_date->format('Y/m/d H:i') }}
- + + @if ($user->isMe()) - - + + @endif
diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 5daf319..5b0be88 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -55,40 +55,8 @@
@yield('tab-content') diff --git a/resources/views/user/likes.blade.php b/resources/views/user/likes.blade.php new file mode 100644 index 0000000..7c78f50 --- /dev/null +++ b/resources/views/user/likes.blade.php @@ -0,0 +1,25 @@ +@extends('user.base') + +@section('title', $user->display_name . ' (@' . $user->name . ') さんがいいねしたチェックイン') + +@section('tab-content') +@if ($user->is_protected && !$user->isMe()) +

+ このユーザはいいね一覧を公開していません。 +

+@else +
    + @forelse ($likes as $like) +
  • + @component('components.ejaculation', ['ejaculation' => $like->ejaculation]) + @endcomponent +
  • + @empty +
  • +

    まだ何もいいと思ったことがありません。

    +
  • + @endforelse +
+ {{ $likes->links(null, ['className' => 'mt-4 justify-content-center']) }} +@endif +@endsection diff --git a/routes/web.php b/routes/web.php index 23eca8e..6eba7e1 100644 --- a/routes/web.php +++ b/routes/web.php @@ -19,6 +19,7 @@ Route::get('/user', 'UserController@redirectMypage')->middleware('auth'); Route::get('/user/{name?}', 'UserController@profile')->name('user.profile'); Route::get('/user/{name}/stats', 'UserController@stats')->name('user.stats'); Route::get('/user/{name}/okazu', 'UserController@okazu')->name('user.okazu'); +Route::get('/user/{name}/likes', 'UserController@likes')->name('user.likes'); Route::get('/checkin/{id}', 'EjaculationController@show')->name('checkin.show'); Route::middleware('auth')->group(function () { From 5bafe9126ac009f9831fda4a5ba7efd953c672c0 Mon Sep 17 00:00:00 2001 From: shibafu Date: Sat, 6 Apr 2019 00:15:54 +0900 Subject: [PATCH 05/19] =?UTF-8?q?=E3=83=98=E3=83=83=E3=83=80=E3=83=BC?= =?UTF-8?q?=E3=83=A1=E3=83=8B=E3=83=A5=E3=83=BC=E3=81=AB=E3=81=84=E3=81=84?= =?UTF-8?q?=E3=81=AD=E4=B8=80=E8=A6=A7=E3=81=B8=E3=81=AE=E3=83=AA=E3=83=B3?= =?UTF-8?q?=E3=82=AF=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/views/layouts/base.blade.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/resources/views/layouts/base.blade.php b/resources/views/layouts/base.blade.php index 38ec46e..14943e4 100644 --- a/resources/views/layouts/base.blade.php +++ b/resources/views/layouts/base.blade.php @@ -50,6 +50,9 @@

+ プロフィール + いいね + 設定 ログアウト
@@ -104,6 +107,9 @@

+ プロフィール + いいね + 設定 @can ('admin') 管理 From 1b4f62119193ea9f8643c5f71cbf518d43f28471 Mon Sep 17 00:00:00 2001 From: shibafu Date: Sat, 6 Apr 2019 00:28:44 +0900 Subject: [PATCH 06/19] fix style --- app/Http/Controllers/Api/LikeController.php | 2 ++ database/migrations/2019_03_26_224641_create_likes_table.php | 4 ++-- routes/api.php | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Api/LikeController.php b/app/Http/Controllers/Api/LikeController.php index 09bf161..d782956 100644 --- a/app/Http/Controllers/Api/LikeController.php +++ b/app/Http/Controllers/Api/LikeController.php @@ -30,10 +30,12 @@ class LikeController extends Controller ], 'ejaculation' => $like->ejaculation ]; + return response()->json($data, 409); } $like = Like::create($keys); + return [ 'ejaculation' => $like->ejaculation ]; diff --git a/database/migrations/2019_03_26_224641_create_likes_table.php b/database/migrations/2019_03_26_224641_create_likes_table.php index 08a59c8..773dbd0 100644 --- a/database/migrations/2019_03_26_224641_create_likes_table.php +++ b/database/migrations/2019_03_26_224641_create_likes_table.php @@ -1,8 +1,8 @@ group(function () { Route::post('/likes', 'Api\\LikeController@store'); Route::delete('/likes/{id}', 'Api\\LikeController@destroy'); -}); \ No newline at end of file +}); From 2cd09402d1ccf5543fce8d943546888122a155e2 Mon Sep 17 00:00:00 2001 From: shibafu Date: Sun, 7 Apr 2019 20:48:29 +0900 Subject: [PATCH 07/19] =?UTF-8?q?=E3=83=81=E3=82=A7=E3=83=83=E3=82=AF?= =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=81=AB=E5=AF=BE=E3=81=99=E3=82=8B=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E3=83=9C=E3=82=BF=E3=83=B3=E3=81=AE=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/assets/sass/app.scss | 8 ++++++- .../views/components/ejaculation.blade.php | 19 ++++++++++------- resources/views/ejaculation/show.blade.php | 21 ++++++++++--------- resources/views/user/profile.blade.php | 21 ++++++++++--------- 4 files changed, 41 insertions(+), 28 deletions(-) diff --git a/resources/assets/sass/app.scss b/resources/assets/sass/app.scss index c3b8f50..0da45fd 100644 --- a/resources/assets/sass/app.scss +++ b/resources/assets/sass/app.scss @@ -14,10 +14,16 @@ $primary: #e53fb1; // Components @import "components/link-card"; +.ejaculation-actions { + & > button:not(:last-child) { + margin-right: 24px; + } +} + .like-button { text-decoration: none !important; } .like-count:not(:empty) { - padding-left: 0.25rem; + padding-left: 0.5rem; } \ No newline at end of file diff --git a/resources/views/components/ejaculation.blade.php b/resources/views/components/ejaculation.blade.php index e32d58a..0203135 100644 --- a/resources/views/components/ejaculation.blade.php +++ b/resources/views/components/ejaculation.blade.php @@ -1,13 +1,9 @@ -
+
{{ $ejaculation->user->display_name }} {{ $ejaculation->ejaculated_date->format('Y/m/d H:i') }}
-
- - -
@if ($ejaculation->tags->isNotEmpty()) @@ -29,7 +25,16 @@ @endif @if (!empty($ejaculation->note)) -

+

{!! Formatter::linkify(nl2br(e($ejaculation->note))) !!}

-@endif \ No newline at end of file +@endif + +
+ + +
\ No newline at end of file diff --git a/resources/views/ejaculation/show.blade.php b/resources/views/ejaculation/show.blade.php index e8f3944..a74bf70 100644 --- a/resources/views/ejaculation/show.blade.php +++ b/resources/views/ejaculation/show.blade.php @@ -30,16 +30,8 @@
-
+
{{ $ejaculatedSpan ?? '精通' }} {{ $ejaculation->before_date }}{{ !empty($ejaculation->before_date) ? ' ~ ' : '' }}{{ $ejaculation->ejaculated_date->format('Y/m/d H:i') }}
-
- - - @if ($user->isMe()) - - - @endif -
@if ($ejaculation->is_private || $ejaculation->tags->isNotEmpty()) @@ -64,10 +56,19 @@ @endif @if (!empty($ejaculation->note)) -

+

{!! Formatter::linkify(nl2br(e($ejaculation->note))) !!}

@endif + +
+ + + @if ($user->isMe()) + + + @endif +
@endif diff --git a/resources/views/user/profile.blade.php b/resources/views/user/profile.blade.php index 2e9493b..22d5cd9 100644 --- a/resources/views/user/profile.blade.php +++ b/resources/views/user/profile.blade.php @@ -36,16 +36,8 @@ @forelse ($ejaculations as $ejaculation)
  • -
    +
    {{ $ejaculation->ejaculated_span ?? '精通' }} {{ $ejaculation->before_date }}{{ !empty($ejaculation->before_date) ? ' ~ ' : '' }}{{ $ejaculation->ejaculated_date->format('Y/m/d H:i') }}
    -
    - - - @if ($user->isMe()) - - - @endif -
    @if ($ejaculation->is_private || $ejaculation->tags->isNotEmpty()) @@ -70,10 +62,19 @@ @endif @if (!empty($ejaculation->note)) -

    +

    {!! Formatter::linkify(nl2br(e($ejaculation->note))) !!}

    @endif + +
    + + + @if ($user->isMe()) + + + @endif +
  • @empty
  • From 4ed2a9048d82b0e4d98052d0b4dfe8b954fce71e Mon Sep 17 00:00:00 2001 From: shibafu Date: Sun, 7 Apr 2019 23:27:24 +0900 Subject: [PATCH 08/19] =?UTF-8?q?=E3=81=84=E3=81=84=E3=81=AD=E3=81=97?= =?UTF-8?q?=E3=81=9F=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BC=E3=81=AE=E4=B8=80?= =?UTF-8?q?=E8=A6=A7=E3=82=92=E8=A1=A8=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Ejaculation.php | 23 +++++++++++++------ resources/assets/sass/app.scss | 4 ++++ .../views/components/ejaculation.blade.php | 13 +++++++++++ resources/views/ejaculation/show.blade.php | 13 +++++++++++ resources/views/user/profile.blade.php | 13 +++++++++++ 5 files changed, 59 insertions(+), 7 deletions(-) diff --git a/app/Ejaculation.php b/app/Ejaculation.php index 3794add..7a8b2a7 100644 --- a/app/Ejaculation.php +++ b/app/Ejaculation.php @@ -46,14 +46,23 @@ class Ejaculation extends Model { if (Auth::check()) { // (ejaculation_id, user_id) でユニークなわけですが、サブクエリ発行させるのとLeft JoinしてNULLかどうかで結果を見るのどっちがいいんでしょうね - return $query->withCount([ - 'likes', - 'likes as is_liked' => function ($query) { - $query->where('user_id', Auth::id()); - } - ]); + return $query + ->with(['likes.user' => function ($query) { + $query->where('is_protected', false) + ->orWhere('id', Auth::id()); + }]) + ->withCount([ + 'likes', + 'likes as is_liked' => function ($query) { + $query->where('user_id', Auth::id()); + } + ]); } else { - return $query->withCount('likes') + return $query + ->with(['likes.user' => function ($query) { + $query->where('is_protected', false); + }]) + ->withCount('likes') ->addSelect('0 as is_liked'); } } diff --git a/resources/assets/sass/app.scss b/resources/assets/sass/app.scss index 0da45fd..0075714 100644 --- a/resources/assets/sass/app.scss +++ b/resources/assets/sass/app.scss @@ -26,4 +26,8 @@ $primary: #e53fb1; .like-count:not(:empty) { padding-left: 0.5rem; +} + +.like-users { + height: 30px; } \ No newline at end of file diff --git a/resources/views/components/ejaculation.blade.php b/resources/views/components/ejaculation.blade.php index 0203135..2a398ff 100644 --- a/resources/views/components/ejaculation.blade.php +++ b/resources/views/components/ejaculation.blade.php @@ -29,6 +29,19 @@ {!! Formatter::linkify(nl2br(e($ejaculation->note))) !!}

    @endif + +@if ($ejaculation->likes_count > 0) +
    +
    + +
    +@endif
    diff --git a/resources/views/user/profile.blade.php b/resources/views/user/profile.blade.php index 22d5cd9..a81cf57 100644 --- a/resources/views/user/profile.blade.php +++ b/resources/views/user/profile.blade.php @@ -66,6 +66,19 @@ {!! Formatter::linkify(nl2br(e($ejaculation->note))) !!}

    @endif + + @if ($ejaculation->likes_count > 0) +
    +
    + +
    + @endif
    From db7dce583030ded509519e16adcf695e44159390 Mon Sep 17 00:00:00 2001 From: shibafu Date: Sun, 7 Apr 2019 23:30:03 +0900 Subject: [PATCH 09/19] =?UTF-8?q?Scss=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E5=88=86=E5=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/assets/sass/app.scss | 19 +------------------ .../assets/sass/components/_ejaculation.scss | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 resources/assets/sass/components/_ejaculation.scss diff --git a/resources/assets/sass/app.scss b/resources/assets/sass/app.scss index 0075714..928bd95 100644 --- a/resources/assets/sass/app.scss +++ b/resources/assets/sass/app.scss @@ -12,22 +12,5 @@ $primary: #e53fb1; @import "tissue.css"; // Components +@import "components/ejaculation"; @import "components/link-card"; - -.ejaculation-actions { - & > button:not(:last-child) { - margin-right: 24px; - } -} - -.like-button { - text-decoration: none !important; -} - -.like-count:not(:empty) { - padding-left: 0.5rem; -} - -.like-users { - height: 30px; -} \ No newline at end of file diff --git a/resources/assets/sass/components/_ejaculation.scss b/resources/assets/sass/components/_ejaculation.scss new file mode 100644 index 0000000..b711fa4 --- /dev/null +++ b/resources/assets/sass/components/_ejaculation.scss @@ -0,0 +1,17 @@ +.ejaculation-actions { + & > button:not(:last-child) { + margin-right: 24px; + } +} + +.like-button { + text-decoration: none !important; +} + +.like-count:not(:empty) { + padding-left: 0.5rem; +} + +.like-users { + height: 30px; +} \ No newline at end of file From e9c1726567e3bda4b36914d603b034c5b5adec91 Mon Sep 17 00:00:00 2001 From: shibafu Date: Sun, 7 Apr 2019 23:44:03 +0900 Subject: [PATCH 10/19] =?UTF-8?q?=E3=81=84=E3=81=84=E3=81=AD=E3=83=A6?= =?UTF-8?q?=E3=83=BC=E3=82=B6=E3=83=BC=E8=A1=A8=E7=A4=BA=E3=81=AE=E9=A0=85?= =?UTF-8?q?=E7=9B=AE=E8=A1=A8=E7=A4=BA=E3=82=92=E3=82=A2=E3=82=A4=E3=82=B3?= =?UTF-8?q?=E3=83=B3=E3=81=8B=E3=82=89=E6=96=87=E5=AD=97=E5=88=97=E3=81=AB?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/views/components/ejaculation.blade.php | 2 +- resources/views/ejaculation/show.blade.php | 2 +- resources/views/user/profile.blade.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/views/components/ejaculation.blade.php b/resources/views/components/ejaculation.blade.php index 2a398ff..af43914 100644 --- a/resources/views/components/ejaculation.blade.php +++ b/resources/views/components/ejaculation.blade.php @@ -32,7 +32,7 @@ @if ($ejaculation->likes_count > 0)
    -
    +
    {{ $ejaculation->likes_count }} 件のいいね
  • - @if ($user->isMe()) - - @endif +
    @yield('tab-content') diff --git a/resources/views/user/likes.blade.php b/resources/views/user/likes.blade.php index 7c78f50..ddb89eb 100644 --- a/resources/views/user/likes.blade.php +++ b/resources/views/user/likes.blade.php @@ -3,7 +3,7 @@ @section('title', $user->display_name . ' (@' . $user->name . ') さんがいいねしたチェックイン') @section('tab-content') -@if ($user->is_protected && !$user->isMe()) +@if (($user->is_protected || $user->private_likes) && !$user->isMe())

    このユーザはいいね一覧を公開していません。

    From fca6b6e98b1de286cd9354cb2ae36d16936012d4 Mon Sep 17 00:00:00 2001 From: shibafu Date: Sun, 14 Apr 2019 00:19:52 +0900 Subject: [PATCH 15/19] =?UTF-8?q?=E3=81=84=E3=81=84=E3=81=AD=E3=83=A6?= =?UTF-8?q?=E3=83=BC=E3=82=B6=E3=83=BC=E8=A1=A8=E7=A4=BA=E3=81=AE=E6=96=87?= =?UTF-8?q?=E5=AD=97=E9=83=A8=E5=88=86=E3=81=AE=E5=B9=85=E3=81=8C=E7=B8=AE?= =?UTF-8?q?=E3=81=BE=E3=81=AA=E3=81=84=E3=82=88=E3=81=86=E3=81=AB=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/views/components/ejaculation.blade.php | 2 +- resources/views/ejaculation/show.blade.php | 2 +- resources/views/user/profile.blade.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/views/components/ejaculation.blade.php b/resources/views/components/ejaculation.blade.php index af43914..7b76bcf 100644 --- a/resources/views/components/ejaculation.blade.php +++ b/resources/views/components/ejaculation.blade.php @@ -32,7 +32,7 @@ @if ($ejaculation->likes_count > 0)
    -
    {{ $ejaculation->likes_count }} 件のいいね
    +
    {{ $ejaculation->likes_count }} 件のいいね