0
votes

Here is my file structure (Laravel 5.2)

/app/http/middleware/Site.php (file one)

/resources/views/layouts/Automotive/text/DefaultText.php (file two)

I have the first file namespaced at App\Http\Middleware

I want to create a new instance of class DefaultText (file two) from within file one.

Doing this does not work:

$config_class = "\\Resources\\Views\\Layouts\\Automotive\\Text\\DefaultText";
new $config_class();

And this does not work either:

$config_class = "\\resources\\views\\layouts\\Automotive\\text\\DefaultText";
new $config_class();

In both instances, it states:

Class '\Resources\Views\Layouts\Automotive\Text\DefaultText' not found

How can I do this?

1
There can be many reasons why. 1. You haven't added the /resources-folder to be mapped to a namespace in the "autoload": { "psr-4": { ... }}-part in your composer.json. 2. You haven't added the correct namespace to your DefaultText-class file. 3. You're not using the same casing (the folder names and the namespace must contain the exact same casing).M. Eriksson
Thanks, I'll try adding to autoload, I didn't do that.Bryce
That was it!! Thank you so much!Bryce
Are you using linux?Jorge SB

1 Answers

0
votes

I needed to add the /resources folder to be mapped to a namespace in the "autoload": { "psr-4": { ... }} part of my composer.json file.

Thank you Magnus Eriksson for the help!