Access Custom config file

Published 1 month ago by sanjayacloud

Hello every one,

I have create a custom config file & I am try to access it from my library. But I get error like below.

Use of undefined constant errorreporter - assumed 'errorreporter' in laravel

This "errorreporter" is my custom config file

MThomas

How are you trying to access it?

Normally you create a file app/config/myconfigfile.php.

And its contents could be

<?php

return [
    'my-item' => 'value'
];

And access it like: config('myconfigfile.my-item').

Does this help?

sanjayacloud

I did like this

if(config('errorreporter.active' )){ $result = $this->store($errorData); }

But it's not work.

MThomas

From where in your app did you do this?

What is the contents of your errorreporter.php file in the config directory?

And what does config('errorreporter.active') actually return?

sanjayacloud

@MThomas have you a got some solution.

MThomas

@sanjayacloud In my first post I showed you how it works, not sure what more you want?

If you are new to Laravel, you might want to start with some of the videos here on Laracasts. And the Laravel Documentation is also a great resource.

sanjayacloud

I am use this config in my custom library(app\libraries\ErrorReporter.php). and config file like this "

return[ 'active' => true, 'mailalert' => false ] "

And my ErrorReporter.php library file like below.

MThomas

Where did you save your config file? Is it in your-app/config/?

sanjayacloud

Yes. Now its ok. But now i try to mass a value when i call in that config but it's not work. but when I change value in my config file to true it's work. can I know how to pass the value for it when I call that config key.

config file:- return [

'active' => false ]

I need this false value change to true when I call in it my library.

newbie360

config(['errorreporter.active' => false]);

saravana2906

Config::get('errorreporter.keyname');

sanjayacloud

@saravana2906 It's not work. I have get 500 error

Please sign in or create an account to participate in this conversation.