/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make(Input::all(), array('name' => 'required', 'description' => 'required', 'url' => 'required|url', 'photo' => 'required|image'));
     if ($validator->fails()) {
         return Response::json($validator->messages(), 400);
     }
     $company = new Company();
     $company->name = Input::get('name');
     $company->description = Input::get('description');
     $company->url = Input::get('url');
     //temporary for territory
     $company->territory_id = 1;
     $company->save();
     //save category and tags if available
     foreach (Input::get('category') as $catid) {
         $company->categories()->attach($catid);
     }
     foreach (Input::get('tag') as $tagid) {
         $company->tags()->attach($tagid);
     }
     $image = Input::file('photo');
     $filename = $company->id;
     $saveBigUrl = base_path() . '/public/images/companies/' . $filename . '.jpg';
     $saveMediumUrl = base_path() . '/public/images/companies/' . $filename . '_medium.jpg';
     $saveSmallUrl = base_path() . '/public/images/companies/' . $filename . '_small.jpg';
     Image::make($image->getRealPath())->fit(600, null, function ($constraint) {
         //for big image
         $constraint->upsize();
     })->save($saveBigUrl, 50)->fit(300)->save($saveMediumUrl, 50)->fit(100)->save($saveSmallUrl, 50);
     $company->big_image_url = url('images/companies/' . $filename . '.jpg');
     $company->medium_image_url = url('images/companies/' . $filename . '_medium.jpg');
     $company->small_image_url = url('images/companies/' . $filename . '_small.jpg');
     $company->save();
     return Response::json(array('success_code' => 'OK', 'data' => $company->toArray()), 201);
 }
Exemple #2
0
 /**
  * Convert to array
  * @return array
  */
 public function toArray()
 {
     $array = array('id_supplier' => $this->getIdSupplier(), 'id_payment_term' => $this->getIdPaymentTerm(), 'id_default_port' => $this->getIdDefaultPort(), 'id_company' => $this->getIdCompany(), 'id_invoice_address' => $this->getIdInvoiceAddress(), 'card_name' => $this->getCardName(), 'rfc' => $this->getRfc(), 'type_person' => $this->getTypePerson(), 'paydays' => $this->getPaydays(), 'id_currency' => $this->getIdCurrency(), 'id_final_grand_risk' => $this->getIdFinalGrandRisk(), 'id_approval_status' => $this->getIdApprovalStatus(), 'quality' => $this->getQuality(), 'consistency' => $this->getConsistency(), 'time' => $this->getTime(), 'type_supplier' => $this->getTypeSupplier());
     return array_merge(parent::toArray(), $array);
 }
Exemple #3
0
 /**
  * Convert to array
  * @return array
  */
 public function toArray()
 {
     $array = array('id_forwarder' => $this->getIdForwarder(), 'id_company' => $this->getIdCompany(), 'name' => $this->getName(), 'last_fee' => $this->getLastFee(), 'status' => $this->getStatus(), 'status_name' => $this->getStatusName());
     return array_merge(parent::toArray(), $array);
 }
Exemple #4
0
 /**
  * Convert to array
  * @return array
  */
 public function toArray()
 {
     $array = array('id_customs_broker' => $this->getIdCustomsBroker(), 'id_company' => $this->getIdCompany(), 'id_last_fee_file' => $this->getIdLastFeeFile(), 'payment' => $this->getPayment(), 'status' => $this->getStatus(), 'status_name' => $this->getStatusName());
     return array_merge(parent::toArray(), $array);
 }
Exemple #5
0
 /**
  * Create a new company
  *
  * @param Company $company
  *
  * @return array
  */
 public function createCompany($company)
 {
     return $this->post('companies', $company->toArray());
 }