How to find a specific file in a Laravel application? - laravel

I have a PHP file located at holiday/app/Console/Commands/myCommand.php with:
namespace Holiday\Console\Commands;
$bob = file_get_contents('Storage/data/BE.json');
and it works.
However in holiday/app/Http/Controllers/holidayController.php I have:
namespace Holiday\Http\Controllers;
$bob = file_get_contents('Storage/data/BE.json');
but I get
file_get_contents(Holiday/Storage/data/BE.json): failed to open stream:
No such file or directory
Does anybody know why this is?

You should always use helpers to get correct path. Here, use storage_path() helper. For instance:
file_get_contents(storage_path('data/BE.json'))
This will create correct path to the laravel_project/storage/data/BE.json file.

Related

Laravel path from Controller to a file

I am trying to implement payment by card in a laravel project. For this i neeed to make a link in Controller to a certificat file.
I put the file in public/files and i made a variable like this
$x509FilePath = '/files/public.cer';
When i'm trying to encrypt an object using this file i get the error
Error while loading X509 public key certificate! Reason:error:02001002:system library:fopen:No such file or directory
error:2006D080:BIO routines:BIO_new_file:no such file
error:02001002:system library:fopen:No such file or directory
error:2006D080:BIO routines:BIO_new_file:no such file
Can anyone help me? Thanks alot!
I think you have to reference the file path using the helper public_path()
Try using:
$x509FilePath = public_path('/files/public.cer');

Laravel pdf issue: failed to open stream: No such file or directory by using barryvdh/laravel-dompdf package

I am update composer and use barryvdh/laravel-dompdf package.
the problem is when i click the button it show me error like image below:-
Is that anyway to change the folder path? or am I missing code to modify path to download the pdf file?
You need to run this command:
php artisan vendor:publish
Then, try to create a fonts directory in the storage directory.
i.e. storage/app/fonts. Also, remember to make it writable.
For maximum execution time of 30 seconds exceeded, this is not laravel related issue but it's about php configuration issue. Please see this and fix it: http://php.net/manual/en/info.configuration.php#ini.max-execution-time
You can also see this answer: https://stackoverflow.com/a/30290770/6000629
Hope this will helps you!
Try this:
$pdf = PDF::loadView('pdf/personalpdf', compact('user','result'))->setOptions(['defaultFont' => 'sans-serif']);
It worked for me, I didn't make any file/folder
Just remove the reference to css external file in your cart.placeOrder.blade
Note: This directory must exist and be writable by the webserver process.
under the config file thats what it say: therefore you should create the fonts directory inside the storage.
"font_cache" => storage_path('fonts/'),

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

Laravel: Why can't I use an 'Orders' directory within App\Controllers

I was able to create the directory, but when I tried to create the namespace App\Http\Controllers\Orders; PHP Storm was showing errors. I could namespace with any other directory name that I tried within \Controllers except for \Orders.
Any ideas why this is?

Resources