PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 26, 2022

[FIXED] Laravel 5.1 defer service provider until another is loaded

 January 26, 2022     laravel, laravel-5.1     No comments   

Issue

I'm using the FormBuilder in Laravel 5.1. The HtmlServiceProvider states the Html and Form facades should defer loading until they are actually needed, which is fine.

However, I have created a FormServiceProvider which registers several macros that I will use in my views. This provider doesn't run any bindings, it simply records a few macros within the FormBuilder class.

However, by storing these macros using the boot method on my own service provider, it's loading the Form binding instantly (making the deferred loading pointless).

Question

Is there any way to defer the boot method in one service provider until another service provider has binded facades?

OR, is there a way to listen for specific binding (or aliasing) events, then manually run a service provider?


Solution

you can listen when container resolves object of any type or when container resolves objects of type XXX as below,

$this->app->resolving(function ($object, $app) {
    // Called when container resolves object of any type...
});

$this->app->resolving(FooBar::class, function (FooBar $fooBar, $app) {
    // Called when container resolves objects of type "FooBar"...
});

here is the DOC



Answered By - Kalhan.Toress
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing