Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 1 year ago.
0

try it like this: http://laravel.io/bin/xm7zv You don't need to all()->get(), just do Rofo::all() because this will already return you the collection. Also status code 200 is unnecessary because it's already the default.

Last updated 1 year ago.
0
Solution

sidneywidmer said:

try it like this: http://laravel.io/bin/xm7zv You don't need to all()->get(), just do Rofo::all() because this will already return you the collection. Also status code 200 is unnecessary because it's already the default.

i have try your suggestion, but still error.

InvalidArgumentException thrown with message "Unexpected data found. Unexpected data found. The separation symbol could not be found The format separator does not match Trailing data"

Stacktrace: #24 InvalidArgumentException in /usr/share/nginx/RESTAPI/vendor/nesbot/carbon/src/Carbon/Carbon.php:385 #23 Carbon\Carbon:createFromFormat in /usr/share/nginx/RESTAPI/bootstrap/compiled.php:7284 #22 Illuminate\Database\Eloquent\Model:asDateTime in /usr/share/nginx/RESTAPI/bootstrap/compiled.php:7134 #21 Illuminate\Database\Eloquent\Model:attributesToArray in /usr/share/nginx/RESTAPI/bootstrap/compiled.php:7124 #20 Illuminate\Database\Eloquent\Model:toArray in /usr/share/nginx/RESTAPI/vendor/laravel/framework/src/Illuminate/Support/Collection.php:713 #19 Illuminate\Support\Collection:Illuminate\Support{closure} in <#unknown>:0 #18 array_map in /usr/share/nginx/RESTAPI/vendor/laravel/framework/src/Illuminate/Support/Collection.php:715 #17 Illuminate\Support\Collection:toArray in /usr/share/nginx/RESTAPI/app/controllers/RofoController.php:13 #16 RofoController:index in <#unknown>:0 #15 call_user_func_array in /usr/share/nginx/RESTAPI/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:231 #14 Illuminate\Routing\Controller:callAction in /usr/share/nginx/RESTAPI/bootstrap/compiled.php:5799 #13 Illuminate\Routing\ControllerDispatcher:call in /usr/share/nginx/RESTAPI/bootstrap/compiled.php:5787 #12 Illuminate\Routing\ControllerDispatcher:dispatch in /usr/share/nginx/RESTAPI/bootstrap/compiled.php:4986 #11 Illuminate\Routing\Router:Illuminate\Routing{closure} in <#unknown>:0 #10 call_user_func_array in /usr/share/nginx/RESTAPI/bootstrap/compiled.php:5345 #9 Illuminate\Routing\Route:run in /usr/share/nginx/RESTAPI/bootstrap/compiled.php:5011 #8 Illuminate\Routing\Router:dispatchToRoute in /usr/share/nginx/RESTAPI/bootstrap/compiled.php:4999 #7 Illuminate\Routing\Router:dispatch in /usr/share/nginx/RESTAPI/bootstrap/compiled.php:722 #6 Illuminate\Foundation\Application:dispatch in /usr/share/nginx/RESTAPI/bootstrap/compiled.php:703 #5 Illuminate\Foundation\Application:handle in /usr/share/nginx/RESTAPI/bootstrap/compiled.php:7763 #4 Illuminate\Session\Middleware:handle in /usr/share/nginx/RESTAPI/bootstrap/compiled.php:8370 #3 Illuminate\Cookie\Queue:handle in /usr/share/nginx/RESTAPI/bootstrap/compiled.php:8317 #2 Illuminate\Cookie\Guard:handle in /usr/share/nginx/RESTAPI/bootstrap/compiled.php:10955 #1 Stack\StackedHttpKernel:handle in /usr/share/nginx/RESTAPI/bootstrap/compiled.php:664 #0 Illuminate\Foundation\Application:run in /usr/share/nginx/RESTAPI/public/index.php:49

So i change with this code:

$rofo = DB::table('rofo')->select('*')->where('CreateID', Auth::user()->id)->get();

return Response::json(array('error' => false,'rofo' => $rofo));

Its work, what the problem with my laravel ?

Last updated 1 year ago.
0

Hi,

the problem is that function toArray() breaks, when the model contains Date Mutators (http://laravel.com/docs/4.2/eloquent#date-mutators).

For me it helped to turn them off by adding this function in the model:

/* We need to disable date mutators, because they brake toArray function on this model */
public function getDates()
{
 return array();
}

Now I was able to run this code:

$merchants = AffiliateMerchant::all();

return Response::json(array(
 'error' => false,
 'merchants' => $merchants->toArray())
);

Regards, Remik

Last updated 8 years ago.
0

I know this thread is super old, but I ran into this problem to and wanted to keep the Carbon date (to handle timezones), so I added a custom jsonify function to my model:

public function jsonify() {
  $columns = $this->getConnection()->getSchemaBuilder()->getColumnListing($this->getTable());
  $record = [];
  foreach($columns as $column) {
    if (is_a($this[$column], 'Carbon\Carbon')) {
      $record[$column] = $this[$column]->format(Carbon::ISO8601);
    } else {
      $record[$column] = $this[$column]        
    }
  }
  return json_encode($record);
}

Just in case there is someone stuck on legacy code and running into the same problem ;)

Last updated 7 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Jayuda jayuda Joined 22 Sep 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.