質問編集履歴
5
誤字
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
親テーブルに送れない変数がある(Field ' ' doesn't have a default value)
|
body
CHANGED
File without changes
|
4
解決コードの記述と記載ミス
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
親テーブルに送れない変数がある(Field ' ' doesn't have a default value)
|
1
|
+
わ親テーブルに送れない変数がある(Field ' ' doesn't have a default value)
|
body
CHANGED
@@ -46,7 +46,7 @@
|
|
46
46
|
{
|
47
47
|
protected $fillable = ['name'];
|
48
48
|
|
49
|
-
public function
|
49
|
+
public function items()
|
50
50
|
{
|
51
51
|
return $this->hasMany('App\branch');
|
52
52
|
}
|
@@ -76,4 +76,19 @@
|
|
76
76
|
OS:Windows10
|
77
77
|
Apache 2.4.38
|
78
78
|
PHP Version 7.1.26
|
79
|
-
Laravel Framework 5.8.4
|
79
|
+
Laravel Framework 5.8.4
|
80
|
+
|
81
|
+
---
|
82
|
+
かなりとんちんかんなことをしていましたが,回答頂いた情報+コントローラの下記の書き換えで動かすことができました。
|
83
|
+
後学のために。
|
84
|
+
```php
|
85
|
+
$shop_posted = $request->input('shop');
|
86
|
+
$branch_posted = $request->input('branch');
|
87
|
+
|
88
|
+
$shop = new shop;
|
89
|
+
shop::updateOrCreate(['name'=> $shop_posted], ['name'=> $shop_posted]);
|
90
|
+
|
91
|
+
// branch_shop
|
92
|
+
$shop_added = shop::where('name', $shop_posted)->first(); // branchesに追加したオブジェクト
|
93
|
+
$shop_added->branches()->updateOrcreate(['name' => $branch_posted]);
|
94
|
+
```
|
3
コントローラの名前記載ミス
title
CHANGED
File without changes
|
body
CHANGED
@@ -23,7 +23,7 @@
|
|
23
23
|
```
|
24
24
|
【web.php】(Routes)
|
25
25
|
```php
|
26
|
-
Route::post('/', '
|
26
|
+
Route::post('/', 'MyController@store');
|
27
27
|
```
|
28
28
|
【MyController.php】(Controller)
|
29
29
|
```php
|
2
trueではなくfalse
title
CHANGED
File without changes
|
body
CHANGED
@@ -64,8 +64,8 @@
|
|
64
64
|
```
|
65
65
|
### 試したこと
|
66
66
|
|
67
|
-
shopsテーブルやshopモデルの削除→再作成を行ってみましたが,同じ結果でした。
|
67
|
+
- shopsテーブルやshopモデルの削除→再作成を行ってみましたが,同じ結果でした。
|
68
|
-
StrictModeに関する情報を
|
68
|
+
- StrictModeに関する情報を参考に,database.phpにて 'mysql' => ['prefix_indexes' => false] としてみましたが,
|
69
69
|
```
|
70
70
|
"SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`my_db`.`shops`, CONSTRAINT `shops_branch_id_foreign` FOREIGN KEY (`branch_id`) REFERENCES `branchs` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) (SQL: insert into `shops` (`name`, `updated_at`, `created_at`) values (店名, 2019-03-15 02:22:53, 2019-03-15 02:22:53)) ◀"
|
71
71
|
```
|
1
viewにおけるinputeのミス修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -17,8 +17,8 @@
|
|
17
17
|
【index.blade.php】(View)
|
18
18
|
```php
|
19
19
|
<form action="/" method="POST" class="form-horizontal">
|
20
|
-
<input type="text" name="item" class="form-control" placeholder="商品" autocomplete="off">
|
21
20
|
<input type="text" name="shop" class="form-control" placeholder="店名" autocomplete="off">
|
21
|
+
<input type="text" name="branch" class="form-control" placeholder="支店" autocomplete="off">
|
22
22
|
</form>
|
23
23
|
```
|
24
24
|
【web.php】(Routes)
|