app\models\Product::findProductByKey PHP Метод

findProductByKey() публичный статический Метод

public static findProductByKey ( $key ) : mixed
$key
Результат mixed
    public static function findProductByKey($key)
    {
        return Product::scope()->where('product_key', '=', $key)->first();
    }

Usage Example

 private function prepareItem($item)
 {
     $fields = ['cost' => 0, 'product_key' => '', 'notes' => '', 'qty' => 1];
     foreach ($fields as $key => $val) {
         if (!isset($item[$key])) {
             $item[$key] = $val;
         }
     }
     // if only the product key is set we'll load the cost and notes
     if ($item['product_key'] && (!$item['cost'] || !$item['notes'])) {
         $product = Product::findProductByKey($item['product_key']);
         if ($product) {
             if (!$item['cost']) {
                 $item['cost'] = $product->cost;
             }
             if (!$item['notes']) {
                 $item['notes'] = $product->notes;
             }
         }
     }
     return $item;
 }
All Usage Examples Of app\models\Product::findProductByKey