What does the make() method do in Laravel?

Viewed 11834

In the Laravel documentation, I found the following - https://laravel.com/docs/5.4/container#the-make-method

but I am still confused as to what exactly the make() method does. I know the create() method uses the make() method and then persists them into the database, so does make() methods just temporarily save it in php tinker or something? Sorry, I'm Laravel noob. I'm trying to figure out these functions. Thank you! :)

2 Answers

I discovered recently that when you use make (), you are installing the class and you can access the methods of that class or model, this is a useful for the Test and validate that you are getting what you want Example: User model

class User extends Authenticatable
{
public function getRouteKeyName ()
     {
         return 'name';
     }
}

Test user

class UserTest extends TestCase
{
  public function route_key_name_is_set_to_name ()
     {
       $ user = factory (User :: class) -> make ();
       $ this-> assertEquals ('name', $ user-> getRouteKeyName ());
       // When you access the getRouteKeyName method you get the return, that is 'name'
     }
}

On the other hand if you use "create" that would give an error because you are creating a user

Related