Laravel Storage is not able to locate file in Windows - php

I am developing a package on Windows which publishes the package.php file in config directory of Laravel.
To get contents of package.php I am using Storage Facade. (I know I can use config() to read it but my usecase is different.)
use Illuminate\Support\Facades\Storage;
$contents = Storage::get(config_path('package.php'));
The above code is throwing FileNotFoundException but I have checked that the file is present there and I am also able to access it using config() helper.
File not found at path: C:/xampp/htdocs/blog/config/package.php
Interestingly when I print the config_path('package.php') it returns
"C:\xampp\htdocs\blog\config\package.php"
Notice that the direction of slashes is different in the path shown in
Exception message and the path returned by config_path() helper.
I work mostly on Linux and hence not have much idea about Windows so I am not able to understand what;s going on here.
Please help!
Thanks.

Storage::get() will look only inside the root location configured for the disk.
https://laravel.com/docs/8.x/filesystem#retrieving-files
You can use File facade instead of Storage.
File::get(config_path('package.php'));

Related

Larverl's response()->file() must be prefixed with the current directory

On a fresh Laravel 8 installation I follow these steps:
php artisan storage:link
Inside /public/storage/ I create folder images/ and inside I paste an image called picture.png
In web.php I define a route like this:
Route::get('/picture', function(
return response()->file(Storage::url("images/picture.png"));
))
However, if I visit this route in browser, the picture is not shown and the following error is thrown:
Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException
The file "/storage/images/picture.png" does not exist
It works only if the url inside response()->file() is prefixed with ./ indicating the current directory like this:
return response()->file('./'.Storage::url("images/picture.png"));
I don't think it is a good idea to work with relative paths locally, the Storage and file methods should handle this. Maybe it is even an issue with the framework.
Any ideas how to go around this hack?
I think you didn't configure the local driver check the documentation https://laravel.com/docs/8.x/filesystem#the-public-disk and look for local driver.
If you configure it right it should return the "/" that you're adding manually.

CodeIgniter: The configuration file ion_auth.php does not exist.

I have been using modules in my project is written with CodeIgniter.
What I have
Folders
-->application
-->cache
-->config
-->config.php (configuration file for auth, I copied the codes to config.php)
-->controllers
-->core
-->errors
-->helpers
-->hooks
-->language
-->libraries
-->auth's libraries files.
-->logs
-->models
-->modules
-->admin
-->controllers
-->auth.php
-->models
-->ion_auth_model.php
-->views
-->auth
-->login.php
-->home
-->third_party
-->views
-->assets
-->system
What the problem is
When I go to localhost/home/auth/login.php, an error message is occurred. On the screen is written
An Error Was Encountered
The configuration file ion_auth.php does not exist.
I guess the problem is about the iounauth configuration file will be moved config folder before setup. I didnt moved it to config folder. Instead of it, I copied all the codes from that file, to the config.php
So how can I solve this problem? I need to see the login screen instead of this error message. I think I should change some lines on auth.php in controller folder. Because I am using config.php instead of ionauth.php for config folder.
I've just had a quick scan of the ion_auth Library and model and the easiest thing to do would be:
Remove $this->load->config('ion_auth', TRUE); from both the library and model.
do a string replace in both the library and model:
FIND: , 'ion_auth') REPLACE WITH: )
I have done a quick scan of the files and I can't see anywhere where this would break anything but just be careful when you're doing it (maybe do it one at a time).
The above to steps should allow you to use the ion_auth config items in your config.php
Please note that I have not tested this.
Hope this helps!
I'm also facing this issue when move my web to linux server, it solved by renaming config/Ion_auth.php to config/ion_auth.php

How to get config data in laravel in a subfolder

I have the Laravel Administrator Plugin and I set up a setting administrator page that is located in:
app/config/administrator/settings/site.php
The application can store the data, but when i try to get some data in one of my controllers like this:
Config::get('administrator.settings.site')
I can get a returned value... Always null or array 0.
How I can get those configuration values?
Solution:
You can use a file path rather than dot notation for file paths:
Config::get('administrator/settings/site.variable_name');
Some Explanation
Dot notation is used to get variables inside the config array within a file, rather than to denote file paths.
Therefore you can use Config::get('administrator/settings/site.variable_name'); to get $variable_name from administrator/settings/site.php, or ENV_DIR_NAME/administrator/settings/site.php depending on your environment.
Directories within in app/config are read as environments. For example app/development/database.php will work with Config::get('database.whatever') when you're in your "development" environment while app/production/database.php will be read with Config::get('database.whatever') when you're in the "production" environment.
Laravel falls back to the config/config/*.php file when no environment-specific file is present.
Note
I believe that admin package has a config file in app/config/packages/frozennode/administrator/administrator.php which the package would like you to use for it's settings. That should be available using this convention: Config::get('package::file.option');
I ran into a very similar problem when using this Laravel-Excel package.
The solution I needed was slightly different to the solution above. I needed to take advantage of Laravel's config overriding feature to have one config setting for normal execution and a different one for testing. Specifically, I normally wanted Excel files to be stored in storage/excel and I wanted them to be put in storage/testing/excel under testing.
The technique of using a slashed path didn't work because it points to a specific file so didn't respect the different environments:
$directory = Config::get('packages/maatwebsite/excel/export.store.path');
The solution was to use a package prefix so that the config loader would respect the environment:
$directory = Config::get('excel::export.store.path');
I'm not exactly sure where the excel shorthand name comes from but I suspect it's something to do with the Excel facade in the package exposing itself as 'excel'.

Including PHP files with Laravel framework

I am trying to "include" a php script into one of my views (landing.blade.php).
The script is in:
/laravel-master/public/assets/scripts/config.php
When I try to include this code in the view:
<?php include_once('/assets/scripts/config.php'); ?>
I get the error: include_once(/assets/scripts/config.php): failed to open stream: No such file or directory
This is on localhost using MAMP. I'm not sure if there is a different set of rules I need to use with Laravel 4 to include a php file. Thank you for your help!
First, it's not really recommended that you keep your PHP files in the public directory, they should be kept inside the app folder. I'd suggest you create a folder inside app, something like includes and put your files there. Then, you include it, do:
include(app_path().'/includes/config.php');
Although, since it looks like you're trying to load some configuration files, I'd recommend you also check out Laravel's own way of handling configurations. For instance, if you created a myapp.php file inside the app/config folder, Laravel would handle it automatically for you, as long as you'd have some key-value pairs, like this:
<?php
return [
'name' => 'Raphael',
'gorgeous' => true
];
You could then retrieve these values using the Config class:
Config::get('myapp.name'); // Raphael
This is a better solution because you can also take advantage of Laravel's environment configuration.
You can use includes in HTML forget about concatenation
#include('foldername.filename')
#include('filename')
This is another way:
require 'file path';

Error with propel-generate-crud in Symfony 1.0

When I try to generate a CRUD test for a new project I am getting a PHP Warning and a Fatal Error.
The errors relate to files that it cannot find, however, I have checked and the files are definitely there.
The error text is 'require_once(lib/model/map/QuestionMapBuilder.php): failed to open stream: No such file or directory in c:\webroot\askeet\lib\model\om\BaseQuestionPeer.php on line 547'
What details of my project should I check?
I think it's a problem with your include path.
Check it, the require_once() call is looking for lib/model/map/QuestionMapBuilder.php
But your include_path is C:\webroot\askeet\lib
Which, when resolved together into a full path, would look like this
C:\webroot\askeet\lib\lib\model\map\QuestionMapBuilder.php
So, I think your solution is to add C:\webroot\askeet to your include path.
You are generating crud for the Question model class but it doesn't seem to exist. Documentation on using the crud generator
First you must use the schema.yml file to define your database, and run
./symfony propel:build-model
to generate your model files. (this will generate lib\model\map\QuestionMapBuilder.php)
I finally tracked down the issue. In my PHP.ini files, they were setup wit the default UNIX file path settings.
Weirdly nothing had ever been broken by this incorrect configuration. Plus, everything in Symfony had worked up until now.
I have switched to Windows style file_path and all is well again.
Thanks for all the answers!

Categories