What do you mean by extending facades? Facades are just a proxy for an underlying implementation in the service container...in other words a proxied shortcut to mainly make code more readable. I don't see why you would want to extend a specific Facade. If you want to create a custom facade so that an implementation is proxied in the service container, that sounds like it could be useful. But, that's just my opinion.
Issues Extending Response Facade in Laravel 5.2
To return a json formatted response, normally at the end of each controller method I do something like:
return response()->json($data);
I have standardized a response message format in json tjhat I send to the browser. To avoid exposing the structure of the response to every method of every controller I've created a helper class of sorts. The methods in this class are designed to support method chaining so the intent is to allow controllers to call something like:
return response()->setDataJson($data)->redirect('url')->notify('message')->send();
Behind the scenes each of these methods help construct an array with various default values and the send() method basically just calls Laravel's Reponse facade json() method to convert the array to json.
While prototyping I got this working by simply instantiating my custom response class in my controller's constructor like this (notice I pass a ResponseFactory instance to the constructor)...
$this->response = new MyResponse(response());
and then changing how I access the response by doing this:
return $this->response->setDataJson($data)->redirect('url')->notify('message')->send();
Of course this work so my class is doing what it's supposed to do. The problem is this seems kind of hackey and I want to use the original syntax above "response()->set...." To do this I assumed that I would have to create a Facade, or more appropriately, extend the stock Laravel Response facade.
Toward that end I followed this technique:
http://slashnode.com/new-response-types-laravel-using-custom-facades/
Everything seems like it's provisioned correctly and yet I get "BadCallMethodExceptions" related to the first custom method in my class I attempt to call (setDataJson). The only obvious difference between my implementation and the referenced one is that my methods are not declared static, but I can't see why that should matter. I'm simply extending a class and PHP places no such restrictions on the method declaration.
Does anyone have a better reference on how to extend Laravel Facades (other than paid videos)?
Please or to participate in this conversation.