質問編集履歴
3
記述ミス
test
CHANGED
File without changes
|
test
CHANGED
@@ -908,13 +908,13 @@
|
|
908
908
|
|
909
909
|
@foreach($datas as $data)
|
910
910
|
|
911
|
-
{{ $data->id }}
|
911
|
+
id{{ $data->id }}
|
912
|
-
|
912
|
+
|
913
|
-
{{ $data->books->title }}
|
913
|
+
本の名前{{ $data->books->title }}
|
914
|
-
|
914
|
+
|
915
|
-
{{ $data->users->name }}
|
915
|
+
借りての名前{{ $data->users->name }}
|
916
|
-
|
916
|
+
|
917
|
-
{{ $data->
|
917
|
+
貸し出し日{{ $data->lent_date }}
|
918
918
|
|
919
919
|
<br>
|
920
920
|
|
2
whereNullに変更してエラー文を追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,11 +16,127 @@
|
|
16
16
|
|
17
17
|
```
|
18
18
|
|
19
|
-
|
19
|
+
Trying to get property 'title' of non-object
|
20
|
-
|
20
|
+
|
21
|
-
```
|
21
|
+
```
|
22
|
+
|
22
|
-
|
23
|
+
dd(&datas)をしてみたところ
|
24
|
+
|
23
|
-
|
25
|
+
```
|
26
|
+
|
27
|
+
Illuminate\Database\Eloquent\Collection {#310 ▼
|
28
|
+
|
29
|
+
#items: array:1 [▼
|
30
|
+
|
31
|
+
0 => App\Models\Lending {#312 ▼
|
32
|
+
|
33
|
+
#table: "lendings"
|
34
|
+
|
35
|
+
#fillable: array:5 [▼
|
36
|
+
|
37
|
+
0 => "user_id"
|
38
|
+
|
39
|
+
1 => "book_id"
|
40
|
+
|
41
|
+
2 => "lent_date"
|
42
|
+
|
43
|
+
3 => "return_date"
|
44
|
+
|
45
|
+
4 => "status"
|
46
|
+
|
47
|
+
]
|
48
|
+
|
49
|
+
+timestamps: false
|
50
|
+
|
51
|
+
#connection: "sqlite"
|
52
|
+
|
53
|
+
#primaryKey: "id"
|
54
|
+
|
55
|
+
#keyType: "int"
|
56
|
+
|
57
|
+
+incrementing: true
|
58
|
+
|
59
|
+
#with: []
|
60
|
+
|
61
|
+
#withCount: []
|
62
|
+
|
63
|
+
+preventsLazyLoading: false
|
64
|
+
|
65
|
+
#perPage: 15
|
66
|
+
|
67
|
+
+exists: true
|
68
|
+
|
69
|
+
+wasRecentlyCreated: false
|
70
|
+
|
71
|
+
#attributes: array:6 [▼
|
72
|
+
|
73
|
+
"id" => "2"
|
74
|
+
|
75
|
+
"user_id" => "2"
|
76
|
+
|
77
|
+
"book_id" => "3"
|
78
|
+
|
79
|
+
"lent_date" => "2021-6-30"
|
80
|
+
|
81
|
+
"return_date" => null
|
82
|
+
|
83
|
+
"status" => "0"
|
84
|
+
|
85
|
+
]
|
86
|
+
|
87
|
+
#original: array:6 [▼
|
88
|
+
|
89
|
+
"id" => "2"
|
90
|
+
|
91
|
+
"user_id" => "2"
|
92
|
+
|
93
|
+
"book_id" => "3"
|
94
|
+
|
95
|
+
"lent_date" => "2021-6-30"
|
96
|
+
|
97
|
+
"return_date" => null
|
98
|
+
|
99
|
+
"status" => "0"
|
100
|
+
|
101
|
+
]
|
102
|
+
|
103
|
+
#changes: []
|
104
|
+
|
105
|
+
#casts: []
|
106
|
+
|
107
|
+
#classCastCache: []
|
108
|
+
|
109
|
+
#dates: []
|
110
|
+
|
111
|
+
#dateFormat: null
|
112
|
+
|
113
|
+
#appends: []
|
114
|
+
|
115
|
+
#dispatchesEvents: []
|
116
|
+
|
117
|
+
#observables: []
|
118
|
+
|
119
|
+
#relations: []
|
120
|
+
|
121
|
+
#touches: []
|
122
|
+
|
123
|
+
#hidden: []
|
124
|
+
|
125
|
+
#visible: []
|
126
|
+
|
127
|
+
#guarded: array:1 [▼
|
128
|
+
|
129
|
+
0 => "*"
|
130
|
+
|
131
|
+
]
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
]
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
```
|
24
140
|
|
25
141
|
### 該当のソースコード
|
26
142
|
|
@@ -770,7 +886,7 @@
|
|
770
886
|
|
771
887
|
{
|
772
888
|
|
773
|
-
$datas = Lending::where('return_date'
|
889
|
+
$datas = Lending::whereNull('return_date')->get();
|
774
890
|
|
775
891
|
return view('index', ['datas' => $datas]);
|
776
892
|
|
1
seederファイルの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
表題の通りです。
|
6
6
|
|
7
|
-
ビューで貸し出しテーブルにリレーションしたusersテーブルのnameとbooksテーブルのtitleを表示させたいです。
|
7
|
+
ビューで貸し出しテーブルにリレーションしたusersテーブルのnameとbooksテーブルのtitleを表示させたいです。そのうえで貸し出しテーブルのreturn_dateがnullの値を抽出したいです。
|
8
8
|
|
9
9
|
ですがリレーション先へのアクセスができなくて詰まっています。
|
10
10
|
|
@@ -546,6 +546,198 @@
|
|
546
546
|
|
547
547
|
```
|
548
548
|
|
549
|
+
### シーダー
|
550
|
+
|
551
|
+
```
|
552
|
+
|
553
|
+
// database/seeder/UserSeeder
|
554
|
+
|
555
|
+
<?php
|
556
|
+
|
557
|
+
|
558
|
+
|
559
|
+
namespace Database\Seeders;
|
560
|
+
|
561
|
+
|
562
|
+
|
563
|
+
use Illuminate\Database\Seeder;
|
564
|
+
|
565
|
+
use Illuminate\Support\Facades\DB;
|
566
|
+
|
567
|
+
use Illuminate\Support\Facades\Hash;
|
568
|
+
|
569
|
+
|
570
|
+
|
571
|
+
class UserSeeder extends Seeder
|
572
|
+
|
573
|
+
{
|
574
|
+
|
575
|
+
/**
|
576
|
+
|
577
|
+
* Run the database seeds.
|
578
|
+
|
579
|
+
*
|
580
|
+
|
581
|
+
* @return void
|
582
|
+
|
583
|
+
*/
|
584
|
+
|
585
|
+
public function run()
|
586
|
+
|
587
|
+
{
|
588
|
+
|
589
|
+
for ($i = 1; $i <= 10; $i++) {
|
590
|
+
|
591
|
+
DB::table('users')->insert([
|
592
|
+
|
593
|
+
'id' => $i,
|
594
|
+
|
595
|
+
'name' => 'user' . $i,
|
596
|
+
|
597
|
+
'email' => 'email' . $i . '@gmail.com',
|
598
|
+
|
599
|
+
'password' => Hash::make('password'),
|
600
|
+
|
601
|
+
]);
|
602
|
+
|
603
|
+
}
|
604
|
+
|
605
|
+
}
|
606
|
+
|
607
|
+
}
|
608
|
+
|
609
|
+
|
610
|
+
|
611
|
+
```
|
612
|
+
|
613
|
+
```
|
614
|
+
|
615
|
+
//database/seeder/BookSeeder
|
616
|
+
|
617
|
+
<?php
|
618
|
+
|
619
|
+
|
620
|
+
|
621
|
+
namespace Database\Seeders;
|
622
|
+
|
623
|
+
|
624
|
+
|
625
|
+
use Illuminate\Database\Seeder;
|
626
|
+
|
627
|
+
use Illuminate\Support\Facades\DB;
|
628
|
+
|
629
|
+
|
630
|
+
|
631
|
+
class BookSeeder extends Seeder
|
632
|
+
|
633
|
+
{
|
634
|
+
|
635
|
+
/**
|
636
|
+
|
637
|
+
* Run the database seeds.
|
638
|
+
|
639
|
+
*
|
640
|
+
|
641
|
+
* @return void
|
642
|
+
|
643
|
+
*/
|
644
|
+
|
645
|
+
public function run()
|
646
|
+
|
647
|
+
{
|
648
|
+
|
649
|
+
for ($i = 1; $i <= 10; $i++) {
|
650
|
+
|
651
|
+
DB::table('books')->insert([
|
652
|
+
|
653
|
+
'title' => 'title' . $i,
|
654
|
+
|
655
|
+
]);
|
656
|
+
|
657
|
+
}
|
658
|
+
|
659
|
+
}
|
660
|
+
|
661
|
+
}
|
662
|
+
|
663
|
+
|
664
|
+
|
665
|
+
```
|
666
|
+
|
667
|
+
```
|
668
|
+
|
669
|
+
// database/seeder/LendingSeeder
|
670
|
+
|
671
|
+
<?php
|
672
|
+
|
673
|
+
|
674
|
+
|
675
|
+
namespace Database\Seeders;
|
676
|
+
|
677
|
+
|
678
|
+
|
679
|
+
use Illuminate\Support\Facades\DB;
|
680
|
+
|
681
|
+
use Illuminate\Database\Seeder;
|
682
|
+
|
683
|
+
|
684
|
+
|
685
|
+
class LendingSeeder extends Seeder
|
686
|
+
|
687
|
+
{
|
688
|
+
|
689
|
+
/**
|
690
|
+
|
691
|
+
* Run the database seeds.
|
692
|
+
|
693
|
+
*
|
694
|
+
|
695
|
+
* @return void
|
696
|
+
|
697
|
+
*/
|
698
|
+
|
699
|
+
public function run()
|
700
|
+
|
701
|
+
{
|
702
|
+
|
703
|
+
DB::table('lendings')->insert([
|
704
|
+
|
705
|
+
'user_id' => '1',
|
706
|
+
|
707
|
+
'book_id' => '2',
|
708
|
+
|
709
|
+
'lent_date' => '2021-6-30',
|
710
|
+
|
711
|
+
'return_date' => '2021-7-4',
|
712
|
+
|
713
|
+
'status' => '0',
|
714
|
+
|
715
|
+
]);
|
716
|
+
|
717
|
+
|
718
|
+
|
719
|
+
DB::table('lendings')->insert([
|
720
|
+
|
721
|
+
'user_id' => '2',
|
722
|
+
|
723
|
+
'book_id' => '3',
|
724
|
+
|
725
|
+
'lent_date' => '2021-6-30',
|
726
|
+
|
727
|
+
'return_date' => null,
|
728
|
+
|
729
|
+
'status' => '0',
|
730
|
+
|
731
|
+
]);
|
732
|
+
|
733
|
+
}
|
734
|
+
|
735
|
+
}
|
736
|
+
|
737
|
+
|
738
|
+
|
739
|
+
```
|
740
|
+
|
549
741
|
### コントローラ
|
550
742
|
|
551
743
|
```
|