質問編集履歴
2
route\.php/ArticlesController\.phpの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -284,4 +284,274 @@
|
|
284
284
|
|
285
285
|
|
286
286
|
|
287
|
+
|
288
|
+
|
289
|
+
routes.phpとArticlesController.phpを追記しました。
|
290
|
+
|
291
|
+
cssフレームワークは、laravel5.2にbootstrapが入っているので、そちらを使いたいです。
|
292
|
+
|
287
|
-
|
293
|
+
度々、すみませんがよろしくお願いします。
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
```
|
300
|
+
|
301
|
+
routes.php
|
302
|
+
|
303
|
+
?php
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
Route::get('/', 'ArticlesController@getIndex');
|
308
|
+
|
309
|
+
Route::controller('articles', 'ArticlesController');
|
310
|
+
|
311
|
+
```
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
```ここに言語を入力
|
316
|
+
|
317
|
+
ArticlesController.php
|
318
|
+
|
319
|
+
<?php
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
namespace App\Http\Controllers;
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
use App\Article;
|
328
|
+
|
329
|
+
use App\Http\Requests;
|
330
|
+
|
331
|
+
use App\Http\Controllers\Controller;
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
use Illuminate\Http\Request;
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
class ArticlesController extends Controller
|
342
|
+
|
343
|
+
{
|
344
|
+
|
345
|
+
/**
|
346
|
+
|
347
|
+
* @var Article
|
348
|
+
|
349
|
+
* 一覧、詳細、作成、編集、削除のアクションをそれぞれ定義する
|
350
|
+
|
351
|
+
*/
|
352
|
+
|
353
|
+
protected $article;
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
/**
|
360
|
+
|
361
|
+
* @param Article $article
|
362
|
+
|
363
|
+
*/
|
364
|
+
|
365
|
+
public function __construct(Article $article)
|
366
|
+
|
367
|
+
{
|
368
|
+
|
369
|
+
$this-> article = $article;
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
}
|
374
|
+
|
375
|
+
/**
|
376
|
+
|
377
|
+
* 記事の一覧
|
378
|
+
|
379
|
+
*
|
380
|
+
|
381
|
+
* @return \Illuminate\View\View
|
382
|
+
|
383
|
+
*/
|
384
|
+
|
385
|
+
public function getIndex()
|
386
|
+
|
387
|
+
{
|
388
|
+
|
389
|
+
$articles = $this->article->all();
|
390
|
+
|
391
|
+
return view('articles.index')->with(compact('articles'));
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
}
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
/**
|
400
|
+
|
401
|
+
* 記事の詳細
|
402
|
+
|
403
|
+
*
|
404
|
+
|
405
|
+
* @param $id
|
406
|
+
|
407
|
+
* @return \Illuminate\View\View
|
408
|
+
|
409
|
+
*/
|
410
|
+
|
411
|
+
public function getShow($id)
|
412
|
+
|
413
|
+
{
|
414
|
+
|
415
|
+
$article = $this->article->find($id);
|
416
|
+
|
417
|
+
return view('articles.show',compact('article'));
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
}
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
/**
|
426
|
+
|
427
|
+
* 記事の投稿
|
428
|
+
|
429
|
+
* GET/articles/createの場合はgetCreate()
|
430
|
+
|
431
|
+
* POST/articles/createの場合はpostCreate()
|
432
|
+
|
433
|
+
* @return \Illuminate\View\View
|
434
|
+
|
435
|
+
*/
|
436
|
+
|
437
|
+
public function getCreate()
|
438
|
+
|
439
|
+
{
|
440
|
+
|
441
|
+
return view('articles.create');
|
442
|
+
|
443
|
+
}
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
/**
|
448
|
+
|
449
|
+
* 記事の投稿
|
450
|
+
|
451
|
+
*
|
452
|
+
|
453
|
+
*
|
454
|
+
|
455
|
+
* @param Request $request
|
456
|
+
|
457
|
+
* @return \Illuminate\Http\RedirectResponse
|
458
|
+
|
459
|
+
*/
|
460
|
+
|
461
|
+
public function postCreate(Request $request)
|
462
|
+
|
463
|
+
{
|
464
|
+
|
465
|
+
$data = $request->all();
|
466
|
+
|
467
|
+
$this->article->fill($data);
|
468
|
+
|
469
|
+
$this->article->save();
|
470
|
+
|
471
|
+
|
472
|
+
|
473
|
+
return redirect()->to('articles/index');
|
474
|
+
|
475
|
+
}
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
/**
|
482
|
+
|
483
|
+
* 記事の編集
|
484
|
+
|
485
|
+
*
|
486
|
+
|
487
|
+
* @param $id
|
488
|
+
|
489
|
+
* @return \Illuminate\View\Viwe
|
490
|
+
|
491
|
+
*/
|
492
|
+
|
493
|
+
public function getEdit($id)
|
494
|
+
|
495
|
+
{
|
496
|
+
|
497
|
+
$article = $this->article->find($id);
|
498
|
+
|
499
|
+
|
500
|
+
|
501
|
+
return view('articles.edit')->withArticle($article);
|
502
|
+
|
503
|
+
}
|
504
|
+
|
505
|
+
|
506
|
+
|
507
|
+
|
508
|
+
|
509
|
+
/**
|
510
|
+
|
511
|
+
* 記事の編集
|
512
|
+
|
513
|
+
*
|
514
|
+
|
515
|
+
* @param Request $request
|
516
|
+
|
517
|
+
* @param $id
|
518
|
+
|
519
|
+
* @return \Illuminate\Http\RedirectResponse
|
520
|
+
|
521
|
+
*/
|
522
|
+
|
523
|
+
|
524
|
+
|
525
|
+
|
526
|
+
|
527
|
+
|
528
|
+
|
529
|
+
/**
|
530
|
+
|
531
|
+
* 記事の削除
|
532
|
+
|
533
|
+
*
|
534
|
+
|
535
|
+
* @param $id
|
536
|
+
|
537
|
+
* @return \Illuminate\Http\RedirectResponse
|
538
|
+
|
539
|
+
*/
|
540
|
+
|
541
|
+
public function postDelete($id)
|
542
|
+
|
543
|
+
{
|
544
|
+
|
545
|
+
$article = $this->article->find($id);
|
546
|
+
|
547
|
+
$article->delete();
|
548
|
+
|
549
|
+
|
550
|
+
|
551
|
+
return redirect()->to('articles/index');
|
552
|
+
|
553
|
+
}
|
554
|
+
|
555
|
+
|
556
|
+
|
557
|
+
```
|
1
エラー内容を追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -271,3 +271,17 @@
|
|
271
271
|
@endsection
|
272
272
|
|
273
273
|
```
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
エラー内容についてです。
|
278
|
+
|
279
|
+
編集ボタンを押すと以下のように表示されます。
|
280
|
+
|
281
|
+
ErrorException in UrlGenerator.php line 602:
|
282
|
+
|
283
|
+
Action App\Http\Controllers\ArticlesController@postEdit not defined. (View: C:\Users\Laravel_practice\resources\views\articles\edit.blade.php)
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
他にも必要なことがあれば、どんどん言って下さい。
|