forked from buri1126/Portfolio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfollowcode
More file actions
58 lines (54 loc) · 2.52 KB
/
Copy pathfollowcode
File metadata and controls
58 lines (54 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Route::get('/users/{user}/follow','follow')->name('follow');
Route::get('/users/{user}/follower','follower')->name('follower');
@if (!Auth::user()->isFollowed($post->user->id))
@if (Auth::user()->isFollowing($post->user->id))
<span class="follows">
<button id="button1" value="フォロー中" class=" follow-toggle" data-user-id="{{ $post->user->id }}"></button>
<button id="button2"value="フォローする" class=" follow-toggle" data-user-id="{{ $post->user->id }}"></button>
</span>
@else
<span class="follows">
<button id="button1" value="フォローする" class=" follow-toggle" data-user-id="{{ $post->user->id }}"></button>
<button id="button2" value="フォロー中" class=" follow-toggle" data-user-id="{{ $post->user->id }}"></button>
</span>
@endif
@else
//フォローする->フォローバック
@if (Auth::user()->isFollowing($post->user->id))
<span class="follows">
<button id="button1" value="フォロー中" class=" follow-toggle" data-user-id="{{ $post->user->id }}"></button>
<button id="button2"value="フォローバック" class=" follow-toggle" data-user-id="{{ $post->user->id }}"></button>
</span>
@else
<span class="follows">
<button id="button1" value="フォローバック" class=" follow-toggle" data-user-id="{{ $post->user->id }}"></button>
<button id="button2" value="フォロー中" class=" follow-toggle" data-user-id="{{ $post->user->id }}"></button>
</span>
@endif
@endif
$(function () {
$('#button2').toggle();
let follow = $('.follow-toggle');
let followedUserId;
like.on('click', function () {
let $this = $(this);
followedUserId = $this.data('user-id');
$.ajax({
headers: {
'X-CSRF-TOKEN' : $('meta[name="csrf-token"]').attr('content')
},
url: '/users/{user}follow',
method: 'POST',
data: {
'follow_id': followedUserId
},
})
.done(function (data) {
$('#button1').toggle();
$('#button2').toggle();
})
.fail(function () {
console.log('fail');
});
});
});