質問編集履歴

3

追記します

2018/08/08 00:13

投稿

aoki_monpro
aoki_monpro

スコア45

test CHANGED
File without changes
test CHANGED
@@ -28,10 +28,6 @@
28
28
 
29
29
  ```
30
30
 
31
-
32
-
33
-
34
-
35
31
  <?php
36
32
 
37
33
 
@@ -90,6 +86,10 @@
90
86
 
91
87
  ・$customerを取得
92
88
 
89
+ ```
90
+
91
+
92
+
93
93
  dd($customer->toArray());
94
94
 
95
95
  array:5 [▼
@@ -106,6 +106,10 @@
106
106
 
107
107
  ]
108
108
 
109
+ ```
110
+
111
+
112
+
109
113
 
110
114
 
111
115
  指定していないcustomer_id が含まれていたのでプログラムどこか間違っていそうです。。

2

変数なしでddをかけてみました。

2018/08/08 00:12

投稿

aoki_monpro
aoki_monpro

スコア45

test CHANGED
File without changes
test CHANGED
@@ -73,3 +73,133 @@
73
73
  }
74
74
 
75
75
  ```
76
+
77
+
78
+
79
+ 2018/08/08追記
80
+
81
+ コメント頂いた内容を試してみました。
82
+
83
+
84
+
85
+ ・変数無しで dd($last_insert_id);
86
+
87
+ → null
88
+
89
+
90
+
91
+ ・$customerを取得
92
+
93
+ dd($customer->toArray());
94
+
95
+ array:5 [▼
96
+
97
+ "customer_name" => "test0902"
98
+
99
+ "visible_flag" => 1
100
+
101
+ "updated_at" => "2018-08-08 09:02:26"
102
+
103
+ "created_at" => "2018-08-08 09:02:26"
104
+
105
+ "customer_id" => 54
106
+
107
+ ]
108
+
109
+
110
+
111
+ 指定していないcustomer_id が含まれていたのでプログラムどこか間違っていそうです。。
112
+
113
+
114
+
115
+ ```migration
116
+
117
+ public function up()
118
+
119
+ {
120
+
121
+ Schema::create('customers', function (Blueprint $table) {
122
+
123
+ $table->increments('id');
124
+
125
+ $table->integer('customer_id');
126
+
127
+ $table->string('customer_name');
128
+
129
+ $table->boolean('visible_flag');
130
+
131
+ $table->integer('sortNo');
132
+
133
+ $table->timestamps();
134
+
135
+ });
136
+
137
+ }
138
+
139
+ ```
140
+
141
+
142
+
143
+ model
144
+
145
+ ```
146
+
147
+ class Customer extends Model
148
+
149
+ {
150
+
151
+ //
152
+
153
+ protected $primaryKey = "customer_id";
154
+
155
+ //
156
+
157
+ public function tasks()
158
+
159
+ {
160
+
161
+ return $this->hasMany('App\Task');
162
+
163
+ }
164
+
165
+
166
+
167
+ }
168
+
169
+
170
+
171
+ ```
172
+
173
+
174
+
175
+ テーブル
176
+
177
+ ```mysql
178
+
179
+ show columns from customers;
180
+
181
+
182
+
183
+ +---------------+------------------+------+-----+---------+----------------+
184
+
185
+ | Field | Type | Null | Key | Default | Extra |
186
+
187
+ +---------------+------------------+------+-----+---------+----------------+
188
+
189
+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment |
190
+
191
+ | customer_id | int(11) | NO | | NULL | |
192
+
193
+ | customer_name | varchar(255) | NO | | NULL | |
194
+
195
+ | created_at | timestamp | YES | | NULL | |
196
+
197
+ | updated_at | timestamp | YES | | NULL | |
198
+
199
+ | visible_flag | tinyint(1) | YES | | NULL | |
200
+
201
+ | sort_no | int(11) | YES | | NULL | |
202
+
203
+ +---------------+------------------+------+-----+---------+----------------+
204
+
205
+ ```

1

id ・・ インクリメントidのことです。

2018/08/08 00:11

投稿

aoki_monpro
aoki_monpro

スコア45

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- フォームからPOST送信しmysql保存した後のidを取得したいのですが、
5
+ フォームからPOST送信しmysql保存した後のid(インクリメントid)を取得したいのですが、
6
6
 
7
7
  下記コードを実行すると、 mysql保存までは確認できるのですが、
8
8