teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

Signup.blade.phpとLoginapp.blade.phpの追加

2019/12/09 08:30

投稿

twinparadox
twinparadox

スコア42

title CHANGED
File without changes
body CHANGED
@@ -182,4 +182,196 @@
182
182
  </body>
183
183
 
184
184
  </html>
185
+ ```
186
+ > Signup Blade.php
187
+ ```
188
+ @extends('layouts.Loginapp')
189
+
190
+ @section('title')
191
+ 新規登録
192
+ @endsection
193
+
194
+ @section('form')
195
+ <p>名前</p>
196
+ <p class="name"><input type="text" name="name" maxlength="32" autocomplete="OFF" /></p>
197
+ <p>メールアドレス</p>
198
+ <p class="mailaddress"><input type="text" name="mailaddress" maxlength="32" autocomplete="OFF" /></p>
199
+ <p>パスワード</p>
200
+ <p class="password"><input type="password" name="password" maxlength="32" autocomplete="OFF" /></p>
201
+ <p>パスワード(確認用)</p>
202
+ <p class="Confirm password"><input type="password" name="password_confirmation" maxlength="32" autocomplete="OFF" /></p>
203
+ <p class="submit"><input type="submit" value="登録" class="top-username" href={{ route('Home')}}></p>
204
+ @endsection
205
+ ```
206
+ > Loginapp.blade.php
207
+ ```
208
+ <!DOCTYPE html>
209
+ <html lang="ja">
210
+
211
+ <head>
212
+ <meta charset="utf-8">
213
+ <title>@yield('title')</title>
214
+ <link rel="stylesheet" type="text/css" href="login.css" media="all" />
215
+ <style>
216
+ body,
217
+ p,
218
+ form,
219
+ input {
220
+ margin: 0
221
+ }
222
+
223
+
224
+ .top-login {
225
+ position: absolute;
226
+ right: 120px;
227
+ top: 18px;
228
+ color: lightcoral;
229
+ text-decoration: none;
230
+ }
231
+
232
+ .top-signup {
233
+ position: absolute;
234
+ right: 30px;
235
+ top: 18px;
236
+ color: lightcoral;
237
+ text-decoration: none;
238
+ }
239
+
240
+ #form {
241
+ width: 350px;
242
+ margin: 30px auto;
243
+ padding: 20px;
244
+ border: 1px solid #555;
245
+ }
246
+
247
+ form p {
248
+ font-size: 14px;
249
+ }
250
+
251
+ .form-title {
252
+ font-size: 20px;
253
+ text-align: center;
254
+ margin-bottom: 20px;
255
+ border-bottom: solid 3px #fff;
256
+ "
257
+
258
+ }
259
+
260
+ .name {
261
+ margin-bottom: 20px;
262
+ }
263
+
264
+ .mailaddress {
265
+ margin-bottom: 20px;
266
+ }
267
+
268
+ .password {
269
+ margin-bottom: 20px;
270
+ }
271
+
272
+
273
+ .confirm password {
274
+ margin-bottom: 20px;
275
+ }
276
+
277
+ input[type="text"],
278
+ input[type="password"] {
279
+ width: 350px;
280
+ padding: 4px;
281
+ font-size: 14px;
282
+ margin: 0 auto;
283
+ }
284
+
285
+ .submit {
286
+ text-align: center;
287
+ }
288
+
289
+ /* skin */
290
+
291
+ #form {
292
+ background: #053352;
293
+ background-image: -webkit-linear-gradient(top, #053352, Courier New);
294
+ background-image: -moz-linear-gradient(top, #053352, Courier New);
295
+ background-image: -ms-linear-gradient(top, #053352, Courier New);
296
+ background-image: -o-linear-gradient(top, #053352, Courier New);
297
+ background-image: linear-gradient(to bottom, #053352, Courier New);
298
+ -webkit-border-radius: 6;
299
+ -moz-border-radius: 6;
300
+ border-radius: 6px;
301
+ font-family: Courier New;
302
+ color: #ffffff;
303
+ font-size: 20px;
304
+ padding: 20px 20px 20px 20px;
305
+ text-decoration: none;
306
+ }
307
+
308
+ .submit input {
309
+ background: #f78181;
310
+ background-image: -webkit-linear-gradient(top, #f78181, #f78181);
311
+ background-image: -moz-linear-gradient(top, #f78181, #f78181);
312
+ background-image: -ms-linear-gradient(top, #f78181, #f78181);
313
+ background-image: -o-linear-gradient(top, #f78181, #f78181);
314
+ background-image: linear-gradient(to bottom, #f78181, #f78181);
315
+ -webkit-border-radius: 8;
316
+ -moz-border-radius: 8;
317
+ border-radius: 8px;
318
+ -webkit-box-shadow: 1px 1px 3px #666666;
319
+ -moz-box-shadow: 1px 1px 3px #666666;
320
+ box-shadow: 1px 1px 3px #666666;
321
+ font-family: Courier New;
322
+ color: #ffffff;
323
+ font-size: 16px;
324
+ padding: 10px 20px 10px 20px;
325
+ text-decoration: none;
326
+ }
327
+
328
+ .submit input:hover {
329
+ background: #f5c7c7;
330
+ background-image: -webkit-linear-gradient(top, #f5c7c7, #f5c7c7);
331
+ background-image: -moz-linear-gradient(top, #f5c7c7, #f5c7c7);
332
+ background-image: -ms-linear-gradient(top, #f5c7c7, #f5c7c7);
333
+ background-image: -o-linear-gradient(top, #f5c7c7, #f5c7c7);
334
+ background-image: linear-gradient(to bottom, #f5c7c7, #f5c7c7);
335
+ text-decoration: none;
336
+ }
337
+
338
+ #form {
339
+ background: #053352;
340
+ background-image: -webkit-linear-gradient(top, #053352, Courier New);
341
+ background-image: -moz-linear-gradient(top, #053352, Courier New);
342
+ background-image: -ms-linear-gradient(top, #053352, Courier New);
343
+ background-image: -o-linear-gradient(top, #053352, Courier New);
344
+ background-image: linear-gradient(to bottom, #053352, Courier New);
345
+ -webkit-border-radius: 6;
346
+ -moz-border-radius: 6;
347
+ border-radius: 6px;
348
+ font-family: Courier New;
349
+ color: #ffffff;
350
+ font-size: 20px;
351
+ padding: 20px 20px 20px 20px;
352
+ text-decoration: none;
353
+ }
354
+ </style>
355
+ </head>
356
+
357
+ <body>
358
+ <p><a class="top-login" href={{ route('Login')}}>ログイン</a></p>
359
+ <p><a class="top-signup" href={{ route('Signup')}}>新規登録</a></p>
360
+ <br>
361
+ <br>
362
+ <br>
363
+ <br>
364
+ <br>
365
+ <br>
366
+ <div id="form">
367
+
368
+ <p class=form-title>@yield('title')</p>
369
+ <form method="POST" action="/Home">
370
+ {{ csrf_field() }}
371
+ @yield('form')
372
+ </form>
373
+ </div>
374
+ </body>
375
+
376
+ </html>
185
377
  ```

1

web.phpとコントローラーの修正

2019/12/09 08:30

投稿

twinparadox
twinparadox

スコア42

title CHANGED
File without changes
body CHANGED
@@ -6,10 +6,7 @@
6
6
  #試したこと
7
7
  csrf_fieldの適用
8
8
 
9
- /HomeをURLで直接入力してみた。↓以下のエラーが発生しました。
10
9
 
11
- どなたか教えて頂けないでしょうか?
12
- ![イメージ説明](46bfcf064acd242306a99f5959e6f7bb.png)
13
10
 
14
11
  以下コード
15
12
  > CreateUserRequest.php
@@ -74,10 +71,20 @@
74
71
 
75
72
  return view('Lessons.Signup');
76
73
  }
77
- public function Home(CreateUserRequest $request)
74
+ public function Home(Request $request)
78
75
  {
79
- $validated = $request->validated();
76
+ $name = $request->input('name');
77
+ return view('Lessons.Home', compact('name'));
80
78
  }
79
+ public function postCreate(CreateUserRequest $req)
80
+ {
81
+ /**
82
+ * 拡張クラスに書いたルールでリクエストが自動的に検証される
83
+    * バリデーションをパスするとこの後の処理が実行される
84
+    */
85
+ $this->userService->createUser($req->all());
86
+ return view('Lessons.Home');
87
+ }
81
88
  }
82
89
 
83
90
  ```
@@ -103,7 +110,10 @@
103
110
 
104
111
  Route::get('Login', 'UserController@Login')->name('Login');
105
112
  Route::get('Signup', 'UserController@Signup')->name('Signup');
106
- Route::post('Home', 'UserController@Home')->name('Home');
113
+ Route::get('Home', 'UserController@Home')->name('Home');
114
+ Route::group(['middleware' => ['web']], function () {
115
+ Route::post('Home', 'UserController@postCreate');
116
+ });
107
117
 
108
118
  ```
109
119
  > Home.blade.php