Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 361 Vote(s) - 3.55 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I include php file in Lumen/Laravel AppServiceProvider register function?

#1
When I tried to custom polymorphic types in a morph relationship, as the spec recommended,

> You may register the morphMap in the boot function of your
> AppServiceProvider or create a separate service provider if you wish.

I added the morpMap function in AppServiceProvider register function (I don't find the boot function in Lumen 5.3 which is used).

class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$propertyConfig = include ('../config/config_property.php');
Relation::morphMap($propertyConfig['property_morph_map']);
}
}
Then, when I tried to run some php artisan commands, it threw this error,

> [ErrorException]
> include(../config/config_property.php): failed to open stream: No such
> file or directory

but the morphMap function does work, which means the address is correct when I run this code on Homestead.

This is my first Lumen project, and I'm still not familiar with the Service Provider. It's kind of weird to me how the register function can influence the artisan command...
Reply

#2
You can load the configure file in `bootstrap/app.php` through below code.

$app->configure('config_property')

To use the configure file in `AppServiceProvider` use `configure()`.

Here is the code.

Relation::morphMap(configure('config_property.property_morph_map'));

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through