Laravel 4: use facade in custom class

I am developing an application using Laravel 4, and I have a question that I would like to ask before I complete it.

I created some custom classes and facades that were successfully added to the laravel configuration file.

For instance:

namespace Helpers; class Ftp { public function connect($data) { // Do something } } 

I use the php use statement to access facades, as usual in Laravel:

 namespace Helpers; use Illuminate\Support\Facades\File; class Ftp { public function Connect($data) { $file = File::get('text.txt'); ... } } 

Now, what is the right way to use lavarel facades inside a custom class? I don’t feel that this is a good choice, especially thinking about testability. Any suggestion appreciated!

+4
source share
1 answer

Just use File. In app / config / app.php, facades get aliases.

 <?php namespace Helpers; class Ftp { public function Connect($data) { $file = \File::get('text.txt'); ... } } 
+5
source

Source: https://habr.com/ru/post/1486816/


All Articles