I'm using Laravel 5.5
and trying to get used to code by psr-2 standard (just started learning). I analyze all my code with Quafoo QA and go step by step fixing the errors and record them.
By using facades i get this error "Avoid using static access to class"
. Because of it i'm trying to avoid using them.
On my controller i have this code:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Events\FileLoaded;
use Illuminate\Support\Facades\Input;
use Illuminate\Auth\Middleware\Authenticate;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use \Illuminate\Contracts\View\Factory as ViewFactory;
class LoadDataController extends Controller
{
public function index()
{
$viewfactory = app(ViewFactory::class);
return $viewfactory->make('LoadData/index');
}
//more code
}
Besides the View Facade
i also use DB, Input, Validator and Storage
Is this the correct way, are there others?
Laravel
provides static interface to methods but those are not really static. So I think you should read about facades inLaravel
. Using aFacade
is not bad in the context ofLaravel
(IMO), it's a featured offered by the framework and it'll not hurt.Facades
are good inLaravel
but as i said i'm trying to learn the standard so i needed a workaround that work's everywhere and not just inLaravel
. Still thanks for the comments and clarifiactions. @ceejayoz inLaravel
it should be a false positive :)