質問編集履歴
2
テーブルを追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -124,6 +124,86 @@
|
|
124
124
|
|
125
125
|
```
|
126
126
|
|
127
|
+
|
128
|
+
|
129
|
+
followsテーブル
|
130
|
+
|
131
|
+
```
|
132
|
+
|
133
|
+
+--------------+------------------+------+-----+-------------------+----------------+
|
134
|
+
|
135
|
+
| Field | Type | Null | Key | Default | Extra |
|
136
|
+
|
137
|
+
+--------------+------------------+------+-----+-------------------+----------------+
|
138
|
+
|
139
|
+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
|
140
|
+
|
141
|
+
| following_id | int(10) unsigned | NO | MUL | NULL | |
|
142
|
+
|
143
|
+
| followed_id | int(10) unsigned | NO | MUL | NULL | |
|
144
|
+
|
145
|
+
| created_at | timestamp | NO | | CURRENT_TIMESTAMP | |
|
146
|
+
|
147
|
+
+--------------+------------------+------+-----+-------------------+----------------+
|
148
|
+
|
149
|
+
```
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
postsテーブル
|
154
|
+
|
155
|
+
```
|
156
|
+
|
157
|
+
+------------+------------------+------+-----+---------+----------------+
|
158
|
+
|
159
|
+
| Field | Type | Null | Key | Default | Extra |
|
160
|
+
|
161
|
+
+------------+------------------+------+-----+---------+----------------+
|
162
|
+
|
163
|
+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
|
164
|
+
|
165
|
+
| user_id | int(10) unsigned | NO | MUL | NULL | |
|
166
|
+
|
167
|
+
| post | varchar(500) | NO | | NULL | |
|
168
|
+
|
169
|
+
| created_at | timestamp | YES | | NULL | |
|
170
|
+
|
171
|
+
| updated_at | timestamp | YES | | NULL | |
|
172
|
+
|
173
|
+
+------------+------------------+------+-----+---------+----------------+
|
174
|
+
|
175
|
+
```
|
176
|
+
|
177
|
+
usersテーブル
|
178
|
+
|
179
|
+
```
|
180
|
+
|
181
|
+
+------------+------------------+------+-----+----------+----------------+
|
182
|
+
|
183
|
+
| Field | Type | Null | Key | Default | Extra |
|
184
|
+
|
185
|
+
+------------+------------------+------+-----+----------+----------------+
|
186
|
+
|
187
|
+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
|
188
|
+
|
189
|
+
| username | varchar(255) | NO | | NULL | |
|
190
|
+
|
191
|
+
| mail | varchar(255) | NO | | NULL | |
|
192
|
+
|
193
|
+
| password | varchar(255) | NO | | NULL | |
|
194
|
+
|
195
|
+
| bio | varchar(400) | YES | | NULL | |
|
196
|
+
|
197
|
+
| images | varchar(255) | YES | | dawn.png | |
|
198
|
+
|
199
|
+
| created_at | timestamp | YES | | NULL | |
|
200
|
+
|
201
|
+
| updated_at | timestamp | YES | | NULL | |
|
202
|
+
|
203
|
+
+------------+------------------+------+-----+----------+----------------+
|
204
|
+
|
205
|
+
```
|
206
|
+
|
127
207
|
上記一覧表示されているaタグをクリックすると、クリックしたユーザーの情報を取得したいと考えております。
|
128
208
|
|
129
209
|
バージョン
|
1
ControlloerとModelを追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -42,6 +42,80 @@
|
|
42
42
|
|
43
43
|
```
|
44
44
|
|
45
|
+
|
46
|
+
|
47
|
+
Controlloer
|
48
|
+
|
49
|
+
```php
|
50
|
+
|
51
|
+
namespace App\Http\Controllers;
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
use Illuminate\Http\Request;
|
56
|
+
|
57
|
+
use Illuminate\Support\Facades\Auth;
|
58
|
+
|
59
|
+
use Illuminate\Support\Facades\DB;
|
60
|
+
|
61
|
+
use App\Post;
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
class PostsController extends Controller
|
66
|
+
|
67
|
+
{
|
68
|
+
|
69
|
+
public function profile(Post $post)
|
70
|
+
|
71
|
+
{
|
72
|
+
|
73
|
+
$user = auth()->user();
|
74
|
+
|
75
|
+
$posts = $post->getPost($post->id);
|
76
|
+
|
77
|
+
dd($posts);
|
78
|
+
|
79
|
+
```
|
80
|
+
|
81
|
+
Model
|
82
|
+
|
83
|
+
```php
|
84
|
+
|
85
|
+
namespace App;
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
use Illuminate\Database\Eloquent\Model;
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
class Post extends Model
|
94
|
+
|
95
|
+
{
|
96
|
+
|
97
|
+
protected $fillable = [
|
98
|
+
|
99
|
+
'user_id', 'post',
|
100
|
+
|
101
|
+
];
|
102
|
+
|
103
|
+
public function getPost($user_id)
|
104
|
+
|
105
|
+
{
|
106
|
+
|
107
|
+
return $this->with('user')->where('id', $user_id)->first();
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
```
|
116
|
+
|
117
|
+
|
118
|
+
|
45
119
|
route
|
46
120
|
|
47
121
|
```php
|