mardi 21 juillet 2020

How to validate relation in request class in laravel?

In My system customer can create product and purchase order. and then that product is can be added in purchase order as purchase order product. now the scenario is customer can add only his own product in purchase order as purchase order product. I want to validate that thing in Request class.

purchase order product Request

public function rules()
    {
        return [
            'purchase_order_id' => 'required|numeric|exists:purchase_orders,id',
            'product_id' => 'required|exists:products,id',

        ];
    }

here I need to check that user can this product belongs to that customer

Product Model

public function customers()
    {
        return $this->belongsTo('App\Models\Customer', 'customer_id');
    }

purchase order

 public function customers()
    {
        return $this->belongsTo('App\Models\Customer', 'customer_id');
    }

    public function purchase_order_products()
    {
        return $this->hasMany('App\Models\PurchaseOrderProduct', 'purchase_order_id');
    }

purchase order product model

public  function products()
    {
        return $this->belongsTo('App\Models\Product', 'product_id');
    }


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3hiosJ5
via IFTTT

Aucun commentaire:

Enregistrer un commentaire