dimanche 8 juillet 2018

Load data from other table using AJAX

When I try to fetch the data using the AJAX option I get an error saying that a column does not exist.

The main table that I am using is users and the other is orders. In the User model I have a relation set between both tables. In that case, the orders table has a user_id as FK.

public function orders()
{
    return $this->hasMany(Order::class);
}

And in the UserCrudController I set the order column to get the data using an accessor:

[
    'label' =>  'Orders',
    'name'  =>  'order_count',
],

// This method is in the `User` model
public function getOrderCountAttribute() {
    return count($this->orders);
}

So when I enable the AJAX I get the error that says that the column order_count does not exist in the User table. The relation and the accessor are not reached because I tried using die().

Is there a way I can run the query using AJAX? I am using backpack 3 and laravel 5.4



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire