Explain make Method in Laravel and what does the make() method do in Laravel?

0 votes
Can anyone explain me about the make method in laravel? And why it is used in laravel?
Mar 19 in Laravel by kartik
• 10,990 points
39 views

1 answer to this question.

0 votes

Hey,

You may use the make method to resolve a class instance out of the container. 

The make method accepts the name of the class or interface you wish to resolve:

$api = $this->app->make(‘HelpSpot\API’);

One advantage to using the make method, is that Laravel will automatically inject any dependencies the class may define in it's constructor.

E.g. an instance of the Mailer class would be automatically injected here.

namespace App\Services;

use \Illuminate\Mail\Mailer;

class MyService
{
    public function __construct(Mailer $mailer) {
        $this->mailer = new Mailer;
    }
}

Hope this is helpful!

Thank you!

answered Mar 19 by Niroj
• 22,110 points

Related Questions In Laravel

0 votes
1 answer

Does Laravel support caching and what are the Cache Usage?

Hey, Yes, Laravel provides support for popular caching ...READ MORE

answered Mar 20 in Laravel by Niroj
• 22,110 points
42 views
0 votes
1 answer

What is the use of the Eloquent cursor() method in Laravel?

Hello, The cursor method allows us to iterate ...READ MORE

answered Mar 20 in Laravel by Niroj
• 22,110 points
105 views
0 votes
1 answer

What is yield in Laravel and what is the use of yield?

Hii kartik, In Laravel, @yield is principally used to define ...READ MORE

answered Mar 23 in Laravel by Niroj
• 22,110 points
825 views
0 votes
1 answer

Explain Extending Bindings in Laravel? And where to extend the bind in laravel?

Hii,  The extend method allows the modification of ...READ MORE

answered Mar 26 in Laravel by Niroj
• 22,110 points
31 views
0 votes
1 answer

What is Laravel framework? Why one should use Laravel?

Laravel is a PHP web-framework; it utilized ...READ MORE

answered Mar 17 in Laravel by Niroj
• 22,110 points
67 views
0 votes
1 answer

How to download and install Lavavel framework?

Hey @kartik, First you must have xampp install ...READ MORE

answered Mar 17 in Laravel by Niroj
• 22,110 points
62 views
0 votes
1 answer

Display Laravel in browser by using cmd promt?

Hello, First you need to have laravel install ...READ MORE

answered Mar 17 in Laravel by Niroj
• 22,110 points
32 views
0 votes
1 answer

How can we get started with Laravel through Xampp?

Hii, First you need to start Apache and ...READ MORE

answered Mar 17 in Laravel by Niroj
• 22,110 points
28 views
0 votes
1 answer

What is the significant difference between insert() and insertGetId() function in Laravel?

Hello, Insert(): This function is simply used to ...READ MORE

answered Mar 17 in Laravel by Niroj
• 22,110 points
43 views
0 votes
1 answer

Explain the concept of encryption and decryption in Laravel?

It is a process of transforming any ...READ MORE

answered Mar 17 in Laravel by Niroj
• 22,110 points
32 views