2 months ago

Model Class instance question

Posted 2 months ago by fdusautoir


I have a question about something.

Consider the following code : App\Models\User::first(). This returns an User class with its attributes like this :

App\Models\User {#2070
     id: 1,
     firstname: "Fran├žois",
     lastname: "Dusautoir",
     email: "[email protected]",
     avatar: null,
     email_verified_at: "2020-07-23 16:45:19",
     settings: "{"lang":"fr","notifications":[]}",
     owner: 1,
     created_at: "2020-07-23 16:45:19",
     updated_at: "2020-07-23 16:45:19",

How is it works to return an instance of the object ? I mean, if I create a simple class like this :

class Test {
  public function first()
    return  [
      'id' => 1,
      'name' => 'John'


(new Test)->first();

It's only returns me a single array, which is normal. But how can I reproduce something like this :

Test {#2069
     id: 1,
     name: "John",

Thanks for your help about it.

Please sign in or create an account to participate in this conversation.