无法显示来自 AJAX Eager Relationship Laravel 的数据
Can't Display the data from AJAX Eager Relationship Laravel
难以在 blade 视图中显示与会者 table 的数据,但在浏览器的网络中显示。在blade中,只显示主模型Activity,与会者的数据只输出object。
我需要输出与会者的数据
例如attendee.fname
我正在使用 yajra 数据 tables:
这是我的ajax
$(document).ready(function(){
$('#student_table').DataTable({
"processing": true,
"serverSide": true,
"ajax": "{{ route('ajaxdata.getdata') }}",
"columns":[
{ data: "ActivityID" },
{ data:"attendee",name:"attendee.fname" } //cant show this need help
]
});
//Heres my controller
function getdata()
{
// $students = Student::select('first_name', 'last_name');
// return Datatables::of($students)->make(true);
//$qr = QR::select('ActivityID', 'AttendeesID');
// return Datatables::of($qr)->make(true);
// $att = Attendee::select('fname','lname')->get();
$qr = QR::with('attendee')->get();
return Datatables::of($qr)->make(true);
}
});
Heres my relationship
public function attendee()
{
return $this->hasMany('App\Attendee','user_id','AttendeesID');
}
public function qr()
{
return $this->belongsTo('App/QR','AttendeesID','user_id');
}
您可以像 { data:"attendee.fname",name:"attendee.fname" }
一样访问数据表中的关系数据
例如attendee.fname
我正在使用 yajra 数据 tables:
这是我的ajax
$(document).ready(function(){
$('#student_table').DataTable({
"processing": true,
"serverSide": true,
"ajax": "{{ route('ajaxdata.getdata') }}",
"columns":[
{ data: "ActivityID" },
{ data:"attendee",name:"attendee.fname" } //cant show this need help
]
});
//Heres my controller
function getdata()
{
// $students = Student::select('first_name', 'last_name');
// return Datatables::of($students)->make(true);
//$qr = QR::select('ActivityID', 'AttendeesID');
// return Datatables::of($qr)->make(true);
// $att = Attendee::select('fname','lname')->get();
$qr = QR::with('attendee')->get();
return Datatables::of($qr)->make(true);
}
});
Heres my relationship
public function attendee()
{
return $this->hasMany('App\Attendee','user_id','AttendeesID');
}
public function qr()
{
return $this->belongsTo('App/QR','AttendeesID','user_id');
}
您可以像 { data:"attendee.fname",name:"attendee.fname" }