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

質問編集履歴

4

web.phpの全文

2020/04/11 11:58

投稿

Himajin_akisyou
Himajin_akisyou

スコア12

title CHANGED
File without changes
body CHANGED
@@ -17,9 +17,45 @@
17
17
 
18
18
  ```php
19
19
  //web.php
20
+ <?php
21
+
22
+ use Illuminate\Support\Facades\Route;
23
+
24
+ /*
25
+ |--------------------------------------------------------------------------
26
+ | Web Routes
27
+ |--------------------------------------------------------------------------
28
+ |
29
+ | Here is where you can register web routes for your application. These
30
+ | routes are loaded by the RouteServiceProvider within a group which
31
+ | contains the "web" middleware group. Now create something great!
32
+ |
33
+ */
34
+
35
+ Route::get('/', function () {
36
+ return view('welcome');
37
+ });
38
+
39
+ //ログイン確認不要
40
+ Route::get('/mypage/{post_id}', 'PostController@edit')->name('edit_post');
41
+ Route::post('/mypage/{post_id}', 'PostController@editing');
42
+
43
+ Route::get('/mypage/{post_id}/{comment_id}')->name('comment_delete');
44
+
45
+
46
+ //ログイン確認必要
47
+ //
48
+ Route::get('/mypage', 'MypageController@index')->name('mypage');
49
+ //新規投稿
50
+ //ここのルートを実行しました
20
51
  Route::get('/mypage/post', function(){
21
52
  return view('create_post');
22
53
  })->name('create_post');
54
+
55
+
56
+ Auth::routes();
57
+ Route::get('/home', 'HomeController@index')->name('home');
58
+
23
59
  ```
24
60
 
25
61
  ```php

3

追記の再修正

2020/04/11 11:58

投稿

Himajin_akisyou
Himajin_akisyou

スコア12

title CHANGED
File without changes
body CHANGED
@@ -83,27 +83,10 @@
83
83
 
84
84
  ###追記
85
85
  ターミナルでphp artisan route:list --name=create_postを実行した結果です。
86
- エラーが出ましたが、そのままコピーして記載しています。
87
86
  ```
88
- Illuminate\Contracts\Container\BindingResolutionException
89
-
90
- Target class [App\Http\Controllers\CommentController] does not exist.
87
+ +--------+----------+-------------+-------------+---------+------------+
91
-
92
- at vendor/laravel/framework/src/Illuminate/Container/Container.php:809
93
- 805|
94
- 806| try {
95
- 807| $reflector = new ReflectionClass($concrete);
88
+ | Domain | Method | URI | Name | Action | Middleware |
96
- 808| } catch (ReflectionException $e) {
97
- > 809| throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
98
- 810| }
99
- 811|
100
- 812| // If the type is not instantiable, the developer is attempting to resolve
89
+ +--------+----------+-------------+-------------+---------+------------+
101
- 813| // an abstract type such as an Interface or Abstract Class and there is
90
+ | | GET|HEAD | mypage/post | create_post | Closure | web |
102
-
103
- 1 [internal]:0
104
- Illuminate\Foundation\Console\RouteListCommand::Illuminate\Foundation\Console\{closure}(Object(Illuminate\Routing\Route))
91
+ +--------+----------+-------------+-------------+---------+------------+
105
-
106
- +12 vendor frames
107
- 14 [internal]:0
108
- Illuminate\Foundation\Console\RouteListCommand::Illuminate\Foundation\Console\{closure}(Object(Illuminate\Routing\Route))
109
92
  ```

2

Post.phpの追記

2020/04/11 07:20

投稿

Himajin_akisyou
Himajin_akisyou

スコア12

title CHANGED
File without changes
body CHANGED
@@ -60,6 +60,27 @@
60
60
 
61
61
  ```
62
62
 
63
+ ```php
64
+ //Post.php
65
+ <?php
66
+
67
+ namespace App;
68
+
69
+ use Illuminate\Database\Eloquent\Model;
70
+
71
+ class Post extends Model
72
+ {
73
+ //
74
+ public function comments(){
75
+ return $this->hasMany('App\Comment');
76
+ }
77
+
78
+ public function user(){
79
+ return $this->belongsTo('App\User');
80
+ }
81
+ }
82
+ ```
83
+
63
84
  ###追記
64
85
  ターミナルでphp artisan route:list --name=create_postを実行した結果です。
65
86
  エラーが出ましたが、そのままコピーして記載しています。

1

php artisan route:list --name=create_postを実行しました

2020/04/11 07:10

投稿

Himajin_akisyou
Himajin_akisyou

スコア12

title CHANGED
File without changes
body CHANGED
@@ -58,4 +58,31 @@
58
58
  }
59
59
  }
60
60
 
61
+ ```
62
+
63
+ ###追記
64
+ ターミナルでphp artisan route:list --name=create_postを実行した結果です。
65
+ エラーが出ましたが、そのままコピーして記載しています。
66
+ ```
67
+ Illuminate\Contracts\Container\BindingResolutionException
68
+
69
+ Target class [App\Http\Controllers\CommentController] does not exist.
70
+
71
+ at vendor/laravel/framework/src/Illuminate/Container/Container.php:809
72
+ 805|
73
+ 806| try {
74
+ 807| $reflector = new ReflectionClass($concrete);
75
+ 808| } catch (ReflectionException $e) {
76
+ > 809| throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
77
+ 810| }
78
+ 811|
79
+ 812| // If the type is not instantiable, the developer is attempting to resolve
80
+ 813| // an abstract type such as an Interface or Abstract Class and there is
81
+
82
+ 1 [internal]:0
83
+ Illuminate\Foundation\Console\RouteListCommand::Illuminate\Foundation\Console\{closure}(Object(Illuminate\Routing\Route))
84
+
85
+ +12 vendor frames
86
+ 14 [internal]:0
87
+ Illuminate\Foundation\Console\RouteListCommand::Illuminate\Foundation\Console\{closure}(Object(Illuminate\Routing\Route))
61
88
  ```