Load config class in App\Libraries in Laravel 5.4 - laravel

H Guys,
I have custom folder in App folder call libraries in laravel 5.2 version.In that libraries folder have a error.php file. I need load my custom config file to the error.php. I have try Config::get('errorreporter.active') & config('errorreporter.active') But these to not work. any one can help me please for resolve this issue

Move the file to the config folder and use the correct naming:
Config::get('[filename].[array_key]');
So if config/error.php has the following content:
<?php
return [
'active' => true
];
then the correct way of calling that value would be
Config::get('error.active')
or
config('error.active')

Related

Call Apache variable in laravel env

So i want to call some apache variables into .env file in laravel 5.4 it is possible ?
You can get Apache variable in one of the config files (existing or a custom one) by using getenv(). Just add similar line to one of config files in /config directory:
'variable' => getenv('APACHE_VARIABLE'),
Then, you'll be able to use this variable in any class and any view of your Laravel application with:
config('configFile.variable')

Laravel 5.1 rename project

What is the best solution if I want to rename my laravel 5.1 project, I just tried to rename one but it did not work properly got some errors.
Are there some kind of steps one has to do to rename a laravel project?
You should use php artisan app:name command to rename your app. It will change namespace in all project files for you. This is the only right way to rename your app.
https://laravel.com/docs/5.0/configuration#after-installation
From laravel version 5.3^ there is a function to call the app name
config('app.name');
You can change the default name 'Laravel' inside this file
config/app.php
'name' => 'Laravel',
And also inside .env file
APP_NAME=Laravel
I just recommend to:
go to .env file at APP-NAME =
put your desired name in "" (double quotes)
restart your server
And you're done.
You can change your project name using the following command:
php artisan app:name your_git_name\your_app_name

How to use SimplePie with Laravel

I am using Laravel 5.2. I need to get RSS feeds using SimplePie, so I install the library through composer.json and now my vendor folder contains simplepie but when i run the following code this error shows:
ErrorException in SimplePie.php line 1379: ./cache is not writeable.
Make sure you've set the correct relative or absolute path, and that
the location is server-writable.
My code in route:
Route::get('feed', function () {
$feed = new SimplePie();
$feed->set_feed_url(array(
'http://www.thenews.com.pk/rss/2/16' //it has no images
));
$feed->init();
$itemCount=$feed->get_item_quantity();
return $itemCount;
});
Create a writeable cache folder for simplepie in the /storage/ folder (I called mine simplepie_cache).
Set the path in your feed object:
$feed->set_cache_location(storage_path() . '/simplepie_cache');
That should do the trick.
check what is saying ./cache is not writeable can't write to cache folder check permissions to this folder or try a L5 wrapper for SimplePie https://github.com/willvincent/feeds

Adding a paths to Laravel 4.1 paths.php

Laravel 4.1 has a file paths.php and it has some paths: app, public, base and storage.
I wish to add another path so what I did:
I wrote this in paths.php
'upload' => __DIR__.'/../some/path/uploads',
Then I copied and pasted and edited this in helpers.php
if ( ! function_exists('upload_path'))
{
function upload_path($path = '')
{
return app()->make('path.upload').($path ? '/'.$path : $;
}
}
But after a few days it disappeared!
I am wondering if I did it wrong.
Never edit files in the vendor directory, it and its contents is entirely managed by Composer, and its contents will be overwritten when doing composer update.
If you want to add your own custom functions, autoload them in your composer.json using the "files" autoload rule.
"autoload": {
"files": ["app/helpers.php"]
}
The "Best" way I found to handle this were the included configuration folders.
Inside root/app/config/ you can add a host specific folder (there is one called local by default).
You can add someFolderName and then inside root/bootstrap/start.php update this array:
$env = $app->detectEnvironment(array(
'local' => array('outLocalHostsName'),
'someFolderName' => array('SomeOtherMachinesHostname'),
));
Now go back to the folder and create an app.php file inside it (remember root/app/config/someFolderName/app.php) and add some value in it like so:
'someKeyNameHere' => 'some path string here'
Now you can access it anywhere using:
Config::get('app.someKeyNameHere')
This seems to work great for me.

Installing a CodeIgniter application in a subfolder

I'm trying to install an application made with codeIgniter in a subfolder, so that I can access it using : http://www.domain.com/my_subfolder/
At the root, there's a Wordpress application.
I edited the .htaccess of the Wordpress install to let the request go to the folder /my_subfolder/
It's working fine, the only problem I get is that CodeIgniter is unable to dynamically load the classes in the "libraries" directory. So everything in the CI application works fine until it tries to use an object declared in the "libraries" subfolder, then I get a : Unable to load the requested class: my_class
It doesn't seems that there's a parameter in the "config" folder to change that... any idea?
What you need is to edit your CodeIgniter config.php in System > application > config.
and then edit config.php and set the property:
$config['base_url'] = "http://www.domain.com/my_subfolder/"
Well it seems that the config param base_url should be updated. Also, I used a library with the "MY_" prefix, and I should'nt since I was'nt extending any CI class.
This is 2021. In case anyone is having this same issue with CodeIgniter 4, this is how I solved it when I came across this issue.
Problem
I installed CI in a subfolder in my public_html folder i.e example.com/api. When I visited www.example.com/api, I saw a 403 forbidden error.
Solution
Download and unzip CI on your local machine or use composer.
Rename public folder to the name of your subfolder. In my case, I named it api.
Create another folder and give it any name of choice, for example, let's use mango (yes, I love mangoes). Copy all the remaining files and folders (app, system, writables, env, LICENSE, README, composer, phpunit, spark) into the mango folder. After doing this, we should have 2 folders: api and mango
Copy both folders to your live server cpanel root (Do not copy into public_html or www). Let them be on the same level as public_html
Open api/index.php and change $pathsConfig = FCPATH . '../app/Config/Paths.php'; to $pathsConfig = FCPATH . '../mango/app/Config/Paths.php';
Create a subdomain and point it to /api
Go to the api folder, duplicate the env file and rename it to .env
Open .env and look for app.baseURL=''. Remove the '#' to uncomment that line and the change it to app.baseUrl='http://subdomain' where subdomain is the subdomain you created above e.g http://api.example.com
Open mango/app/config/App.php and look for public $baseUrl and set it to subdomain e.g $baseUrl = 'http://api.example.com'
Your CI project is now well configured. Visit http://api.example.com. and you should see the CodeIgniter welcome page.

Resources