Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

Can't use models within controllers #2

Closed
eithed opened this issue Jun 4, 2020 · 0 comments
Closed

Can't use models within controllers #2

eithed opened this issue Jun 4, 2020 · 0 comments

Comments

@eithed
Copy link

eithed commented Jun 4, 2020

Hello!

When trying to use the package in controller a file not found exception is raised:

file_get_contents(vendor/mledoze/countries/dist/countries.json): failed to open stream: No such file or directory

I believe this is due to Laravel loading all classes from within ./public folder (within public/index.php) where Composer autoload is triggered

require __DIR__.'/../vendor/autoload.php';

We can confirm this by firing getcwd() within the package like such:

dd(getcwd());
$database = \json_decode(\file_get_contents('vendor/mledoze/countries/dist/countries.json'), true);

which outputs ./public

The workaround is to do:

\file_get_contents(base_path().'/vendor/mledoze/countries/dist/countries.json')

Cheers!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant