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, 2020 in Laravel by kartik
• 37,520 points
5,266 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, 2020 by Niroj
• 82,840 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, 2020 in Laravel by Niroj
• 82,840 points
1,467 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, 2020 in Laravel by Niroj
• 82,840 points
10,824 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, 2020 in Laravel by Niroj
• 82,840 points
29,117 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, 2020 in Laravel by Niroj
• 82,840 points
1,784 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, 2020 in Laravel by Niroj
• 82,840 points
1,702 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, 2020 in Laravel by Niroj
• 82,840 points
1,494 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, 2020 in Laravel by Niroj
• 82,840 points
1,245 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, 2020 in Laravel by Niroj
• 82,840 points
1,046 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, 2020 in Laravel by Niroj
• 82,840 points
2,982 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, 2020 in Laravel by Niroj
• 82,840 points
1,357 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP