0

My db records

Now I admit I am slightly new to laravel still, but to me this just does not make sense. The model that goes along with this table contains only 2 functions, both containing a relationship statement.

I am using Laravel4, mysql, php 5.5

Any ideas are welcome :D

The database record-definitions are for both DATETIME, allow null and no default value (changed that after the screenshots)

the $challenge variable is part of the data I pass on to the view like so:

$challenges = Auth::user()->challenges;
$data['challenges'] = $challenges;

return View::make("challenges/topic", $data);

and in the view I use

@foreach($challenges as $challenge)

read the challenge values (I am aware I cant echo like that without php tags or {{ }}, just easier to explain)

echo gettype($challenge->deadline)   // results in string
echo gettype($challenge->created_at) // results in object
6
  • 1
    Instead of screenshots, which are often hard to read and can't be copy-pasted here, please post plain text. Commented May 8, 2014 at 21:12
  • created_at is Carbon object and deadline is simple datetime string. Read about date mutators in Eloquent. And really, WTF is like 10yr old boy crying, so next time maybe ask real question. Commented May 8, 2014 at 21:28
  • @deczo the WTF was intended to be with a wink, not as a cry out, but appreciated the reaction nontheless. I am well aware of the mutators in Eloquent, the problem is, there is no other code related to those fields, all the steps I took I pasted in the image. The data is brand new and not accessed in any other place :) Commented May 8, 2014 at 21:52
  • I suppose so, that's why I replied anyway. Date mutator are default behaviour for created_at and updated_at so you would need to disable them to notice unusual effects. Commented May 8, 2014 at 21:54
  • @deczo Ah, so created_at and updated_at get special treatment even for how eloquent parses them? meaning I need to pull additional strings for other datetime fields? :) Commented May 8, 2014 at 22:03

1 Answer 1

1

Depends on how you access it, if you do:

Route::any('test', ['as' => 'test', function()
{
    $a = Article::first();

    var_dump( gettype($a->created_at) );

    $a = DB::table('articles')->first();

    var_dump( gettype($a->created_at) );

}]);

You will get:

string 'object' (length=6) /// This is Eloquent

string 'string' (length=6) /// This is the QueryBuilder directly accessing your table
Sign up to request clarification or add additional context in comments.

1 Comment

This is actually very useful, I wasnt aware the QueryBuilder that effect. However I am parsing both values through eloquent, I will add the code to my OP :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.