1
I created a very simple example of using autoload using Composer and PSR-7, but I would like to understand a question, below what I did:
Inside my composer.json
, added the following:
"autoload" : {
"psr-4" : {
"App\\" : "App/"
}
}
Inside the directory App
, I created a very simple class called Log
:
<?php
namespace App;
class Log {
public function gravarLog()
{
return 'Log gravado com sucesso';
}
}
?>
And finally I created a file index.php
, to carry out the test, it was like this:
<?php
require_once 'vendor/autoload.php';
use App\Log;
$log = new App\Log();
echo $log->gravarLog();
It worked right, but I wonder if there is any way to use it in this situation, without the need to always use require_once 'vendor/autoload.php';
so how is it done in Laravel, and how do I do it? Is there a pattern, or a methodology?
Thanks for the return.
– Raphael Godoi