1

i have seen class like where they use facade and register something on acessor.

use Illuminate\Support\Facades\Facade;

/**
 * @see \Collective\Html\FormBuilder
 */
class FormFacade extends Facade {

    /**
     * Get the registered name of the component.
     *
     * @return string
     */
    protected static function getFacadeAccessor() { return 'form'; }

}

it just taken from the laravel package it just returned facade but what actually that return form does ?

1 Answers1

1

Laravel's facades are a sort of "gateway" to a service. It's "syntactic sugar" to make code look more readable. So if you did something like:

Form::open(array('route' => 'route.name'));

What you are actually doing is asking the application to resolve the service provider configured with the name 'form' as it's key. This is another way that it could be done:

app('form')->open(array('route' => 'route.name'));

In reality, you could do it the old fashion way too, but DI (dependency injection) is a great tool:

// Rough example without the actual parameters
$form = new Illuminate\Html\FormBuilder();
$form->open(array('route' => 'route.name'));
Jeremy Harris
  • 24,318
  • 13
  • 79
  • 133
  • why to register here as we have to register form serviceprovider on app.php like 'Form' => Collective\Html\FormFacade::class, –  Dec 09 '15 at 17:29
  • One of the big benefits of this service architecture is if you want to use something else, you can swap out the service the `form` key points at in one place and not have to change code everywhere. – Jeremy Harris Dec 09 '15 at 17:33
  • i dont get you sorry for the inconvenience cause by me –  Dec 09 '15 at 17:42