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

aggy's avatar
Level 4

creating object via php artisan tinker

Hi,

I am viewing the episode "Eloquent Relationships" in Laravel 5 fundamentals and trying to create a user object via PHP Artisan tinker like this:

$user = new App\User; => App\User {#689}

But there is no user object created. I have the standard user class in App and I ran the migration to create the corresponding table. Can anyone help me out here ? Thx ! Aggy

0 likes
2 replies
StormShadow's avatar
Level 51

@aggy you haven't persisted the instance in the database.

You have to assign the properties to that user instance you just newed up and then call save()

$user = new App\User();
 $user->email = 'example@example.com';
$user->username = 'chad'; etc...
$user->save();

Alternatively you can do

App\User::create(['email' => 'example@example.com', ... ]);

See the eloquent documentation.

3 likes
aggy's avatar
Level 4

@StormShadow thx for the quick response. The alternative option works fine! Thank you !

Please or to participate in this conversation.