function Register(Request $request)
 {
     if (!$request->has('organization')) {
         return JSend::fail(['organization' => 'Organization data required']);
     } else {
         $organization_data = $request->input('organization');
         return $this->dispatch(new RegisterOrganization($organization_data, new \App\Models\User()));
     }
 }
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     // Check if location has children
     if ($this->model->children->count()) {
         return JSend::fail(['children' => 'This location has ' . $this->model->children->count() . 'sublocations']);
     }
     // Allow to delete location
     return JSend::success($this->model);
 }
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     // set validation rules
     $rules['name'] = ['required'];
     $rules['level'] = ['required', 'in:continent,country,province,city,suburb'];
     $rules['latitude'] = ['numeric'];
     $rules['longitude'] = ['numeric'];
     // validates
     $validator = Validator::make($this->model->toArray(), $rules);
     if ($validator->fails) {
         return JSend::fail($validator->messages()->toArray());
     } else {
         return JSend::success($this->model);
     }
 }
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     // ------------------------------------------------------------
     // Save Organization
     // ------------------------------------------------------------
     $organization = new Organization($this->organization_data);
     if (!$organization->save()) {
         return JSend::fail($organization->getErrors()->toArray());
     }
     // ------------------------------------------------------------
     // Assign Owner
     // ------------------------------------------------------------
     $this->dispatch(new AddUserToOrganization($organization, $user, true));
     // ------------------------------------------------------------
     // Email Owner
     // ------------------------------------------------------------
     $this->dispatch(new NotifyOwnerAfterOrganizationCreated($organization, $user));
     // ------------------------------------------------------------
     // Email Admin
     // ------------------------------------------------------------
     $this->dispatch(new NotifyOwnerAfterOrganizationCreated($organization, $user));
 }
Beispiel #5
0
 /**
  * Renders the current object into JSend (JSON) string
  *
  * @param   int     $encode_options json_encode() options bitmask
  * @return  string  JSON representation of current object
  * @see     http://php.net/json_encode#refsect1-function.json-encode-parameters
  */
 public function render($encode_options = NULL)
 {
     $data = array();
     foreach ($this->_data as $key => $value) {
         $filter = Arr::get($this->_filters, $key);
         $data[$key] = $this->run_filter($value, $filter);
     }
     $result = array('status' => $this->_status, 'data' => $data);
     /**
      * Error response must contain status & message
      * while code & data are optional
      */
     if ($this->_status === JSend::ERROR) {
         $result['message'] = $this->_message;
         if ($this->_code !== NULL) {
             $result['code'] = $this->_code;
         }
         if (empty($result['data'])) {
             unset($result['data']);
         }
     }
     try {
         $response = JSend::encode($result, $encode_options);
     } catch (JSend_Exception $e) {
         // If encoding failed, create a new JSend error object based on exception
         return JSend::factory()->message($e)->render();
     }
     $this->protect() and $response = ')]}\',' . PHP_EOL . $response;
     return $response;
 }
Beispiel #6
0
 /**
  * @group jsend.run_filter
  * @test
  * @dataProvider provider_run_filter
  * @param mixed $value
  * @param mixed $filter
  * @param mixed $expected
  */
 public function test_run_filter($value, $filter, $expected)
 {
     $jsend = new JSend();
     $return = $jsend->run_filter($value, $filter);
     $this->assertSame($return, $expected);
 }
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     return JSend::fail(['error' => 'Organization cannot be deleted']);
 }