Viewed   124 times

I am quite new to Laravel and implemented the service provider for my helper functions using this answer on SO.

It recommended to:

in the register function of your newly generated HelperServiceProvider.php add following code

require_once app_path('Helpers/AnythingHelper.php');

However, Laravel docs state that register method should only be used to bind things into the container:

As mentioned previously, within the register method, you should only bind things into the service container. You should never attempt to register any event listeners, routes, or any other piece of functionality within the register method.

In my case the app works as it is, with require a statement in the register function, so my question is more about 'best practices' rather than making the code work.

Question:

Is this a good/acceptable approach (require statement in a register method), or should I rather move require statement to the boot method?

 Answers

1

Recommended approach if you put here only methods (not classes):

  1. Create file anywhere you want
  2. In composer.json make sure you add this file to files key inside autoload like this:

    "autoload": {
        // here other autoload things
    
        "files": ["app/Helpers/AnythingHelper.php"]
    },
    
  3. Run composerdump-autoload`

For classes obviously you should use standard PSR-4 autoloading

Sunday, October 23, 2022
 
dvir
 
4

Do you use any antivirus? If yes try to disable then check.

Sometime Mcafe prevent to download packagist.

Wednesday, August 24, 2022
 
stanri
 
5

You should use the URI for the service provider, not necessarily the name of the physical host . So, if your site is "exp.uni.edu", but hosted on the webserver panther-web-07.uni.edu, you'd be safe using something like "https://exp.uni.edu/shibboleth-sp" for your SP entityID. If this SP is running on the webserver for the engineering school at UNI, you could also use something like "https://engineering.uni.edu/shibboleth-sp". It is not required that the entityID resolve, but it should use a namespace your organization owns/controls, and may resolve someday.

Your entityID doesn't necessarily need to be the same as your application's DNS name, since a single Service Provider can protect multiple applications with distinct DNS names running on the same webserver.

You wouldn't want to use the panther-web-07.uni.edu webserver hostname for your entityID, because while the name of the server on which the "exp.uni.edu" site is hosted, the URI for the "exp.uni.edu" hopefully will be static throughout the lifetime of the service.

Friday, September 30, 2022
 
2

It looks like composer install is trying to update packages, so you probably does not have composer.lock file in your project. In that case composer install works like composer update which requires a lot of memory. Your server probably does not have enough memory and process gets killed by OS.

The easiest way of solving this would be to generate composer.lock on dev environment, commit it into project, and then run composer install on server on project with composer.lock. Installing dependencies from composer.lock is cheap, so there should not be any memory-related problems.

If you can't do this, you need to more memory on your server - either enable swap or buy server with more RAM.

Thursday, October 20, 2022
 
1

I could install your package and execute php artisan vendor:publish without any issues, have you tried composer dumpautoload? and php artisan clear-compiled?

Monday, December 5, 2022
 
ipj
 
ipj
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :