I'm new to Laravel service provider, All I want is to pull the database data out and return it, so my config file can access to that data.
How can I do this in Laravel service provider.
I'm new to Laravel service provider, All I want is to pull the database data out and return it, so my config file can access to that data.
How can I do this in Laravel service provider.
Example using the boot method to access database and publish it to a temporary config key.
class YourServiceProvider extends ServiceProvider
{
public function boot()
{
$welcomeMessage = "Welcome " . \App\User::first()->name;
config(['your-namespace.message' => $welcomeMessage ]);
}
Later in other files across your application you can access it like this
Route::get('/', function () {
return config('your-namespace.message');
});