Hello,
Do you declare the relationships in your models ?
V
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
i have this two tables
customer customer table
protected $fillable=
['compy_name','phone','address_name','master_price','customer_type','slave_price','currency'];
customer order table.
protected $fillable=[
'orderNumb',
'customer_id',
'loading_point',
'looade_date',
'border_id',
'team_id',
'truck_number',
'trailer_number',
'master_qty',
'slave_qty',
'user_id' ];
so i want when i select the compy_name, i get their truck_number as well.
i tried like this but does not works
Route::get('customers/{customer}/customer__orders', function (App\Customer_Orders $customer)
{
return response()->json($customer->customer_order->map(function ($customer_order) {
return ['id' => $customer_order->id, 'text' => $customer_order->truck_number];
})
);
});
in my blade
$(document).ready(function(){
$("#customer_id").change(function () {
var options = [];
$.ajax({
method: 'GET',
url: '/customers/' + this.value + '/customer__orders',
success: function (options) {
window.options = options
$('#truck_id').empty()
$('#truck_id').select2({data: options});
}
})
})
})
correct me where i did wrong
Please or to participate in this conversation.