تكون قيم العمود id
خاطئة عندما لا يتم طلب id
من جانب جافا سكريبت.
تظهر المشكلة فقط عندما لا أذكر العمود id
في إعداد dataTables columns
.
$('#table').DataTable({
columns: [
{ data: 'id', name: 'id' }, // ----> Problem appear when i don't mention this column in javascript
{ data: 'user.first_name', name: 'user.first_name' },
...
]
})
في جانب PHP لدي شيء مثل هذا
$students = Student::with(['user', ...]);
return Datatables::of($students)
->addColumn('actions', function ($row)
{
$row->id // ----> Will contain wrong value, it will contain users.id instead of students.id
return $actions;
})
->make(true);
قيمة id
ستكون users.id
بدلاً من students.id
أعتقد أن هذا خطأ في إطار عمل Laravel والعمل على إصلاح ذلك هو عن طريق إضافة select('students.*')
على استعلامك كما هو موثق هنا .
$students = Student::with(['user', ...])->select('students.*');
return Datatables::of($students)
->addColumn('actions', function ($row)
{
$row->id // ----> Will contain wrong value, it will contain users.id instead of students.id
return $actions;
})
->make(true);
شكرا ، انها تعمل بشكل جيد الآن
yajra ، إجابتك ساعدتني ، شكرًا. من الأفضل إزالة التعليق لأنه في المثال الخاص بك يجب أن يكون العكس. سيحتوي على القيمة الصحيحة.
شكر
التعليق الأكثر فائدة
أعتقد أن هذا خطأ في إطار عمل Laravel والعمل على إصلاح ذلك هو عن طريق إضافة
select('students.*')
على استعلامك كما هو موثق هنا .