0
나는 여기에서 내 머리카락을 꺼내, 나는 거의 동일한 elequent 쿼리를해야합니다. 그들은 비슷한 결과를 가져올 수 있어야하지만 그렇지 않습니다. 두 제어기에 ReportsData 출력의 차이Laravel Elequent relationships
테이크 메모 구체적 reports_data "는 [] 관계 예상대로, 제 아무것도 잡아 않는 출력하는 첫 번째 예
..나는 지금 시간 동안 내 머리를 잡아 당겨 된 :(여기
내 코드입니다, 사람이 되거 수 있기를 바랍니다컨트롤러 012 3,
$report = ReportsSuspect::where('id', '=', $id)
->with('serverModel')
->with('reportsReportModel')
->with('reportsReporter')
->with('reportsData')
->get();
$reports = ReportsReport::where('suspect_id', '=', $id)
->with('serverModel')
->with('reportsSuspect')
->with('reportsReporter')
->with('reportsData')
->get();
$ 보고서는 다음
[{"id":4,"steamid":"0987654321","assigned":0,"archived":0,"created_at":"2017-11-30 14:03:45","updated_at":"2017-11-30 14:03:45","server_model":null,"reports_report_model":[{"id":9,"name":"hackerName","offence":"Hacking-ESP\/AIM, Toxic Behaviour","server":25,"suspect_id":4,"reporter_id":3,"created_at":"2017-11-30 14:03:45","updated_at":"2017-11-30 14:03:45"}],"reports_reporter":null,"reports_data":[{"id":16,"reporter_id":3,"suspect_id":4,"moderator_id":0,"comment":null,"url":"image1","comment_type":0,"url_type":1,"created_at":"2017-11-30 14:03:45","updated_at":"2017-11-30 14:03:45"},{"id":17,"reporter_id":3,"suspect_id":4,"moderator_id":0,"comment":null,"url":"video1","comment_type":0,"url_type":2,"created_at":"2017-11-30 14:03:45","updated_at":"2017-11-30 14:03:45"},{"id":18,"reporter_id":3,"suspect_id":4,"moderator_id":0,"comment":"I saw this guy hacking","url":null,"comment_type":1,"url_type":0,"created_at":"2017-11-30 14:03:45","updated_at":"2017-11-30 14:03:45"}]}]
$가 출력 보고서 출력 때라도
[{"id":9,"name":"hackerName","offence":"Hacking-ESP\/AIM, Toxic Behaviour","server":25,"suspect_id":4,"reporter_id":3,"created_at":"2017-11-30 14:03:45","updated_at":"2017-11-30 14:03:45","server_model":{"id":25,"servername":"Rustafied Long","serverlocation":"US","available":1,"servertextname":"US - Long","servertype":1,"serverconnection":"","serverinfo":"","serverpopulation":"","created_at":null,"updated_at":null},"reports_suspect":{"id":4,"steamid":"0987654321","assigned":0,"archived":0,"created_at":"2017-11-30 14:03:45","updated_at":"2017-11-30 14:03:45"},"reports_reporter":{"id":3,"steamid":"76561198363172919","name":"Cake","created_at":"2017-11-30 09:21:40","updated_at":"2017-11-30 09:21:40"},"reports_data":[]}]
ReportsSuspectController
,369 ReportsReportController 1,363,210// Relationship data
public function reportsReport(){
return $this->belongsTo('App\reportsReport', 'reporter_id');
}
public function reportsData(){
return $this->hasMany('App\reportsData', 'suspect_id');
}
public function reportsReportModel(){
return $this->hasMany('App\reportsReport', 'suspect_id');
}
public function reportsReporter(){
return $this->belongsTo('App\reportsReporter', 'id');
}
public function serverModel(){
return $this->belongsTo('App\server', 'server');
}
// Relationship data
public function reportsSuspect(){
return $this->belongsTo('App\reportsSuspect', 'suspect_id');
}
public function reportsReporter(){
return $this->belongsTo('App\reportsReporter', 'reporter_id');
}
public function ReportsData(){
return $this->hasMany('App\reportsData', 'suspect_id');
}
public function serverModel(){
return $this->belongsTo('App\Server', 'server');
}
public function offenceModel(){
return $this->belongsTo('App\Offence', 'offence');
}
reports_data 테이블
id int(10) No None
reporter_id int(11) Yes NULL
suspect_id int(11) Yes NULL
moderator_id int(11) No 0
comment text utf8_unicode_ci Yes NULL
url text utf8_unicode_ci Yes NULL
comment_type int(11) Yes 0
url_type int(11) Yes 0
created_at timestamp Yes NULL
updated_at timestamp Yes NULL
reports_report 테이블
id i nt(10) No None
name text utf8_unicode_ci Yes NULL
offence text utf8_unicode_ci Yes NULL
server int(11) Yes NULL
suspect_id int(11) Yes NULL
reporter_id int(11) Yes NULL
created_at timestamp Yes NULL
updated_at timestamp Yes NULL
,
reports_suspect 표
idPrimary int(10) No None
steamid varchar(25) utf8_unicode_ci Yes NULL
assigned int(11) Yes 0
archived int(11) No 0
created_at timestamp Yes NULL
updated_at timestamp Yes NULL
other_key foreign_key이 필요합니다. ''ReportsReporter'에 대해서'public function ReportsData()'는'reportsData'이어야하고'with ('ReportsData')는'(with reportsData ')'이어야합니다. https://github.com/alexeymezenin/laravel-best-practices # follow-laravel-naming-conventions – cbaconnier
나는 거의 내 자신을 걷어 찼다.하지만 그 문제는 해결되지 않았다. –
외래 키가 잘못 나온 것처럼 위의 코드를 업데이트합니다. 데이터베이스 스키마를 볼 수 있습니까? – cbaconnier