/**
  * @param $data
  *
  * @return static
  */
 public function add($data)
 {
     $this->model->creating(function ($invoice) use($data) {
         $invoice->id = $this->generateInvoiceID();
     });
     $this->model->order()->associate(array_get($data, 'order'));
     return parent::add($data);
 }
예제 #2
0
 /**
  * Creates a user in our system using data from an OAUTH provider API
  *
  * @param SocialiteUser $user
  *
  * @param array $params
  * @return static
  */
 public function createUserUsingDataFromAPI(SocialiteUser $user, $params = [])
 {
     $data = $this->getUserData($user, $params);
     $user = parent::add($data);
     // disable account activation
     $user->confirmed = true;
     $user->confirmation_code = null;
     $user->save();
     return $user;
 }
 /**
  * Add a product to stock
  *
  * @param $data
  *
  * @return static
  */
 public function add($data)
 {
     // create product SKU
     $this->model->creating(function ($product) use($data) {
         $product->sku = $this->generateProductSKU();
         $product->category_id = array_get($data, 'category_id');
         $product->subcategory_id = array_get($data, 'subcategory_id');
         $product->brand_id = array_get($data, 'brand_id');
     });
     return parent::add($data);
 }
 /**
  * @param $data
  *
  * @return mixed
  */
 public function add($data)
 {
     // authenticated user
     $authUser = auth()->user();
     $productID = array_pull($data, 'product_id');
     // associate the review to a product and the currently logged in user
     $this->model->creating(function ($r) use($productID, $authUser) {
         $r->product_id = $productID;
         $r->user_id = $authUser->getAuthIdentifier();
     });
     return parent::add($data);
 }
 /**
  * Adds a shopping cart to the database
  *
  * @param $data
  *
  * @return static
  */
 public function add($data)
 {
     // get the authenticated user
     $authUser = auth()->user();
     $this->model->creating(function ($cart) use($authUser) {
         $cart->id = $this->generateCartID();
         // if a user is logged in, then we will associate this cart to them
         $cart->user_id = $authUser === null ? null : $authUser->getAuthIdentifier();
     });
     $model = parent::add($data);
     return $model;
 }
 /**
  * @param $data
  *
  * @return static
  */
 public function add($data)
 {
     $this->model->creating(function ($order) use($data) {
         $order->id = $this->generateOrderId();
         // add the shopping cart data
         $order->data = array_get($data, 'cart_data');
     });
     $this->performSync($data);
     $order = parent::add([]);
     return $order;
 }