Questions tagged [laravel-facade]

Facades in Laravel framework provide a "static" interface to classes that are available in the application's IoC container.

Facades provide a "static" interface to classes that are available in the application's IoC container. Laravel ships with many facades, and you have probably been using them without even knowing it! Laravel "facades" serve as "static proxies" to underlying classes in the IoC container, providing the benefit of a terse, expressive syntax while maintaining more testability and flexibility than traditional static methods.

168 questions
52
votes
4 answers

Undefined class Route (Laravel in PhpStorm)

How can I fix this alert in PhpStorm? And also how to get autocompletion for Route and other Facades?
Maxim Vasiliev
  • 691
  • 1
  • 6
  • 10
50
votes
6 answers

Using dependency injection over laravel facades

I have read a number of sources that hint that laravel facade's ultimately exist for convenience and that these classes should instead be injected to allow loose coupling. Even Taylor Otwell has a post explaining how to do this. It seems I am not…
myol
  • 8,857
  • 19
  • 82
  • 143
24
votes
1 answer

Laravel Input Facade vs Request Facade

Based on Input Facade API and Request Facade API the Input::get() method seems to be the only difference. Am I missing something here? I know Validation can be applied to Requests, but I am not sure if the same is true for the Input facade.
CrackingTheCode
  • 802
  • 1
  • 11
  • 26
21
votes
3 answers

What is Facades used in Laravel?

I'm confused by the Facades offered by Laravel. The Laravel documentation states: Facades provide a "static" interface to classes that are available in the application's service container. Laravel ships with many facades which provide access to…
Aman Kumar
  • 4,533
  • 3
  • 18
  • 40
13
votes
4 answers

Laravel : Dependency injection vs Facades?

What, I had been doing previously was to inject only MY MODELS using the constructor and use Facades for the Laravel's provided classes i.e. Session, Auth, Validator etc, for example. Will it be a good idea if I inject each and every class (either…
Kamran Ahmed
  • 11,809
  • 23
  • 69
  • 101
12
votes
2 answers

Laravel 5 : Does Auth::user() query the database everytime I use it?

On the edit profile page for a user, I want to show the existing values of the current logged-in user details like name, email, gender etc. My questions are as follows Is it recommendable to user Auth::user()->name , Auth::user()->email directly to…
Prakhar
  • 1,065
  • 3
  • 16
  • 30
10
votes
2 answers

laravel 5 : Extend a Facade

I need to handle different types of DB depending on the client. I created a Facade called MyDBFacade where I can call my own functions. For example: MyDBFacade::createDBUser("MyUser"); // will create a DB user whatever I'm using Postgres or SQL…
Michaël
  • 1,120
  • 1
  • 15
  • 30
10
votes
1 answer

How can I override Laravel Facade methods?

I want to override the Laravels' Mail's classes facade method send (just intercept it forcing some checks and then if it passes triggering parent::send()) What is the best way to do this?
naneri
  • 3,771
  • 2
  • 29
  • 53
8
votes
1 answer

Laravel change filesystem disks path on run time

I am aware of the filesystems.php to create disks and I'm currently using it, having ~~ 20 disks configured. I have a new problem with these, I'm currently trying to prefix to every disk, a string. The problem is that the paths are being saved when…
Sérgio Reis
  • 2,483
  • 2
  • 19
  • 32
7
votes
1 answer

VSCode Intellisense for Laravel Realtime Facades

When using realtime facades in Laravel, VSCode doesn't seems to provide intellisense or autocompletion. Even when using popular plugins like PHP Intelliphense I can't get it to work. However, when I import the class normally it works just fine. For…
UglyBoogaloo
  • 165
  • 1
  • 6
7
votes
4 answers

How to get underlying class name from Facade name in Laravel

I am finding it a bit difficult to understand Facades. Particularly how to find the underlying class name/location from a facade name. I have gone through the documentation but still not clear. For example, when using Auth::login() , i found that…
Yeasir Arafat Majumder
  • 1,222
  • 2
  • 15
  • 34
7
votes
1 answer

How do I update user profile? Laravel-5

Just want to start by saying I have no clue what I'm doing... I have a user_info table that looks like this Schema::create('user_info', function(Blueprint $table){ $table->increments('id'); $table->unsignedInteger('user_id'); …
jackjoesmith
  • 951
  • 4
  • 20
  • 33
6
votes
5 answers

Laravel 7 Fatal error: Uncaught RuntimeException: A facade root has not been set

I have looked at several answers suggested to a similar issue but nothing worked in my case. FYI, this is my first project in Laravel 7, working fine on my Mac. I have deployed the project on my server following this article. When running the…
6
votes
2 answers

PHPUnit Laravel Hash not available

I have a Unit test in Laravel for testing an API call that looks like this, however I am getting the following runtime error when running it: RuntimeException: A facade root has not been set. I'm creating a user in the setup method, with the intent…
Squiggs.
  • 4,299
  • 6
  • 49
  • 89
6
votes
1 answer

Why create a facade in laravel instead of calling a method directly?

I'm just starting with laravel and want to understand this... Lets say we have a class in our application: namespace App\Tests; class MyTest{ public function sayHello($name){ echo "Hello, $name!"; } public static function…
CarlosCarucce
  • 3,420
  • 1
  • 28
  • 51
1
2 3
11 12