Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

thinkjay's avatar

Tinkering in Tinker and failing

I'm following this tutorial: https://laracasts.com/series/laravel-5-fundamentals/episodes/8 If you go to Time: 2:15 I can successfully enter tinker and execture some basic php to test that it is working. But when I try the same code Jeffrey is saying, it's giving me this error

$article = new App\Article; PHP Fatal error: Class 'App\Article' not found in eval()'d code on line 1

I was able to generate the Article.php file in the previous step in the video. Any idea what I'm doing wrong?

0 likes
7 replies
eszterczotter's avatar
Level 31

Did you restart the command line tinker after generating the class? In case tinker is already open when you change code it won't take affect until you exit and tinker again.

Also, check namespaces and a little composer dump-autoload never hurts :)

thinkjay's avatar

@LilyBelle thanks for your help Lily, I think it does have to do with the namespace... I changed 'App' to 'MYPROJECT' and it works, but it's returning this string of numbers, any idea what this means?

$article = new MYPROJECT\Article;
=> <MYPROJECT\Article #000000001b391d690000000154d1b832> {}

I am able to add values to my database but it's still returning that string of numbers

>>> $article->title = 'My First Article';
=> "My First Article"
>>> $article-body = 'Lorem ipsum';
PHP Parse error: Syntax error, unexpected '=' on line 1
>>> $article->body = 'Lorem Ipsum';
=> "Lorem Ipsum"
>>> $article->published_at = Carbon\Carbon::now();
=> <Carbon\Carbon #000000001b391d690000000154d1b832> {
       date: "2015-04-07 16:28:58.000000",
       timezone_type: 3,
       timezone: "UTC"
   }
>>> $article;
=> <stdClass #000000001b391d470000000154c5e732> {
       title: "My First Article",
       body: "Lorem Ipsum",
       published_at: <Carbon\Carbon #000000001b391d690000000154d1b832> {
           date: "2015-04-07 16:28:58.000000",
           timezone_type: 3,
           timezone: "UTC"
       }

Thanks again for your help!

thinkjay's avatar

Disregard, my issue was with the namespace and it's resolved.

jarodrigues's avatar

Hi, guy do you can post the solution? I have even problem

1 like
jwmurray's avatar

I get the same error, however, if I then run:

$article

I find that the object was created, even though I got the error that is mentioned by the OP.

Thus, the code is working, if you can stomach the error message.

Please or to participate in this conversation.