Adding a paths to Laravel 4.1 paths.php - laravel-4

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.

Related

Load config class in App\Libraries in Laravel 5.4

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')

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

How to install or move laravel project on web server

I'm having trouble installing/moving laravel to web server, i downloaded and set laravel on my local linux server but when i moved it to web server ,it shows a blank page.
I uploaded the public folder contents to public_html and other contents outside the public, also i changed the public DIR from paths.php on bootstrap folder as follow: 'public' => __DIR__.'/../public_html/' so what is the exact problem? Please help me with this issue. Is composer a problem? or what?
1) Create a new directory called ‘laravel4′ adjacent to ‘public_html’ so that your remote file structure now looks like this:
[.htpasswds]
[etc]
[laravel4]
[mail]
[public_ftp]
[public_html] etc etc varies depending on server
2) Upload the contents of your local ‘public’ directory to the remote directory ‘public_html’. Note: Be sure not to copy the whole ‘public’ directory, JUST it’s contents.
3) Upload everything else within your local Laravel project to the new remote ‘laravel4′ directory. Check: Now when you view the ‘laravel4′ folder over FTP/SSH/Whatever, you should see all your ‘app’ & ‘bootstrap’ directories along with all the other files and directories, but NOT ‘public’.
4) Edit the remote file ‘public_html/index.php’ and make the following change:
//from:
require __DIR__.'/../bootstrap/autoload.php';
//and
$app = require_once __DIR__.'/../bootstrap/start.php';
//to:
require __DIR__.'/../laravel4/bootstrap/autoload.php';
//and
$app = require_once __DIR__.'/../laravel4/bootstrap/start.php';
5) Edit the remote file ‘laravel4/bootstrap/paths.php’ and make the following change:
//from:
'public' => __DIR__.'/../public',
//to:
'public' => __DIR__.'/../../public_html',
6) That should be it. In my case, that was enough to restructure everything. Routes are working with the default .htaccess file. If you have problems, let me know, or ask on the ever-helpful
Reference: http://myquickfix.co.uk/2013/08/hosting-laravel-4-on-cpanel-type-hosting-public_html/

composer package only for development in laravel providers

If I have a package (that I have to add to app/config/app.php providers/aliases) that I only really want on my development boxes (b/c I only use for development) is there an approach that will allow me to do this leveraging composer require --dev <package> along w/ composer install --no-dev
I need to add an index into both the providers and aliases array...but I would prefer NOT to manage those large arrays in multiple config environment folders if possible
Create a folder in your config directory that matches your environment name. dev in this case.
Next, recreate any files you wish to override and place them into that folder. app.php in this case
Next open bootstrap/start.php and find $app->detectEnvironment. The array passed to this method determines which environment you are working with. Setting the key to this array as dev will overwrite any of your config files with their counterparts in your dev folder.
If you do not wish to create an entirely new providers array in app.php file for each environment and say you only wanted to add a certain provider to your dev environment, you may use a helper method like so...
'providers' => append_config(array(
'DevOnlyServiceProvider',
))
All this information was pulled from the Laravel documentation found here: http://laravel.com/docs/configuration
For anyone looking how to do this in Laravel 5, you can still emulate the L4 behaviour.
On the top of app/Providers/AppServiceProvider add:
use Illuminate\Foundation\AliasLoader;
And then edit the register() method:
public function register()
{
$path = $this->app->environment() .'.app';
$config = $this->app->make('config');
$aliasLoader = AliasLoader::getInstance();
if ($config->has($path)) {
array_map([$this->app, 'register'], $config->get($path .'.providers'));
foreach ($config->get($path .'.aliases') as $key => $class) {
$aliasLoader->alias($key, $class);
}
}
}
Then just add config/<YOUR ENVIRONMENT NAME>/app.php config file and define additional providers and aliases, same as in app.php
For example:
return [
'providers' => [
Barryvdh\Debugbar\ServiceProvider::class,
],
'aliases' => [
'Debugbar' => Barryvdh\Debugbar\Facade::class,
],
];

deploy laravel 4 app in a subdomain

I'm about to deploy laravel 4 on a shared web host into a subdomain and I'm a bit confused about what to do. I got it working on a hostpapa account but wasnt happy with the configuration and switched providers for the testing environment.
I've created the following folders:
domain/private/myApps/golfmanager
I've placed in here all the files and folders except the public folder
I've then placed the contents of the public folder into this folder:
domain/subdomains/golfmanager/httpddocs
I'm not sure what to do now! I understand I need to change the paths in bootstrap/path.php
Can someone provide some pointers of what needs to be changed for this folder set up. Don't want to break it!!
Thanks
This is super easy on shared hosting.
Step 1: Understanding your folder structure. The layout of your shared hosting should generally look something like this:
/
username
home
public_html
subdomain-name
laravel-files (optional)
...other folders etc
As you hopefully know, all your public files for your site will be in your public_html folder.
Note: sometimes a subdomain will be inside the public_html folder. That is okay but I recommend creating your subdomain folder above the root for a little bit of extra security. You can do that easily in cPanel but changing the path to the subdomain when you are creating it.
Step 2: Upload your Laravel files above the root (above public_html) or in a subfolder if you want it to be cleaner.
For a small project I generally upload the files into the "home" folder above. But for cleaner structure you may want to create a folder inside that "home" folder called "laravel-files".
What follows is how to do it in an "laravel-files" folder. If you upload them to "home" instead then all you need to do is get rid of all references to "/laravel-files" below.
Step 3: edit your public/index.php and your bootstrap/paths.php files:
In paths.php
change
'app' => __DIR__.'/../app',
to:
'app' => __DIR__.'/../laravel-files/app',
change:
'public' => __DIR__.'/../public',
to:
'public' => __DIR__,
change:
'base' => __DIR__.'/..',
to:
'base' => __DIR__.'/../laravel-files',
change:
'storage' => __DIR__.'/../app/storage',
to:
'storage' => __DIR__.'/../laravel-files/app/storage',
In index.php
change:
require __DIR__.'/../bootstrap/autoload.php';
to:
require __DIR__.'/../laravel-files/bootstrap/autoload.php';
change:
$app = require_once __DIR__.'/../bootstrap/start.php';
to:
$app = require_once __DIR__.'/../laravel-files/bootstrap/start.php';
Now what you'll need to do is, as I said upload your laravel project to your "laravel files" folder.
The only thing you wont upload there is the contents of your laravel "public" folder, which should instead be uploaded to your "subdomain-name" folder (this includes your index.php and all your css js files etc).
Hope this helps!
Please note my answer is based on this question: How to install Laravel 4 to a web host subfolder without publicly exposing /app/ folder? but tailored for your situation.
I'm not sure this is the way to go, because, since your folders are completely different, it's doable but you probably will need to create symlinks for this to work this way.
Laravel is supposed to have the folder hiearchy you see in your application and you should have
domain/subdomains/golfmanager/httpddocs/app
domain/subdomains/golfmanager/httpddocs/bootstrap
domain/subdomains/golfmanager/httpddocs/public
domain/subdomains/golfmanager/httpddocs/vendor
So, what I think you can do it to put everything on
domain/subdomains/golfmanager/httpddocs
And ask your domain administrator to set the document root of your application to
domain/subdomains/golfmanager/httpddocs/public
This way, when you point your browser to
http://golfmanager.yourdomain.com
It will access this index file:
domain/subdomains/golfmanager/httpddocs/public/index.php
This is how Laravel is supposed to work.
Josh answer was very helpful, but it did not work or did not matched my case.
I will tailor my solution like his one, so everyone could follow easily:
Step 1: My chosen folder structure:
/
home
username
public_html
subdomain-name
laravel-files
...other folders etc
Note: my subdomain is inside the public_html folder.
Step 2: Uploaded my Laravel files above the root (above/out of public_html) in a subfolder: laravel-files (//home/username/laravel-files)
Step 3: edit your public/index.php and your bootstrap/paths.php files:
In paths.php
Don't change:
'app' => __DIR__.'/../app',
to:
'app' => __DIR__.'/../../laravel-files/app',
because it's useless - it will evaluate to the following path:
"/home/username/laravel-files/bootstrap/../../laravel-files/app"
so the default is enough to just get out of bootstrap and enter app.
Instead, change:
'public' => __DIR__.'/../public',
to:
'public' => __DIR__.'/../../public_html/subdomain-name',
Also, don't change:
'base' => DIR.'/..',
'storage' => DIR.'/../app/storage',
In index.php
change:
require __DIR__.'/../bootstrap/autoload.php';
to:
require __DIR__.'/../../laravel-files/bootstrap/autoload.php';
and change:
$app = require_once __DIR__.'/../bootstrap/start.php';
to:
$app = require_once __DIR__.'/../../laravel-files/bootstrap/start.php';
Upload your laravel project to the "laravel-files" folder, except the public folder.
Content of "public" folder, should instead be uploaded to the "subdomain-name" folder.

Resources