Why should someone use this:
function flash($title)
{
$flash = app('App\Http\Flash');
return $flash->message('This is a flash message');
}
over this:
use App\Http\Flash;
function flash($title)
{
$flash = new Flash;
return $flash->message('This is a flash message');
}
In the first case we are getting the available container instance.
In the second case we load the Flash class and instantiate it then in our flash method.
I've seen someone use the first approach and I wonder if there is ANY difference in using the second approach.
If you are using it as in your example - you'll get no profit. But Laravel container gives much more power in this resolving that you cannot achieve with simple instantiating objects.
Countable
interface everywhere as a target to resolve from container but receive it's implementation instead.)And many other practises... You can read more detailed here http://laravel.com/docs/5.1/container
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With