1

I am using excel reader from https://github.com/nuovo/spreadsheet-reader and it is in app folder.

Now when I try to access it from HomeController.php using following code.

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;

use App\spreadsheet_reader\php_excel_reader\excel_reader2;
use App\spreadsheet_reader\SpreadsheetReader;

class HomeController extends Controller
{
    public function index()
   {
        require_once(base_path().'/app/spreadsheet_reader/php_excel_reader/excel_reader2.php');

       $Reader = new \App\spreadsheet_reader\SpreadsheetReader(base_path().'/UnRegisterClient.xlsx');
   }
}

Then it gives me following error.

Class 'App\spreadsheet_reader\SpreadsheetReader' not found

Any suggesstion how I can solve this? I mean how I can use my custom class?

2 Answers 2

4

Put your external files in the folder app/Libraries (first, create the Libraries folder) then just autoload the folder with that file.

For example, add this folder in the array or “classmap” in composer.json :

"autoload": {
    "classmap": [
        "database",
        "app\Libraries"
    ],
    "psr-4": {
        "App\\": "app/"
    }
},

Then run composer dump-autoload in your command line.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for giving suggestions. Up vote for you as well
Great, but somehow this suggestion looks more in a Laravel way, instead of doing require_once everywhere you want to use it.
In a roundabout way this solved my problem. I had created a new directory in App and I needed to add it to the classmap.
2

I think the SpreadsheetReader is not defined in the namespace. You should call just new \SpreadsheetReader(...) or add use SpreadsheetReader and then call it new SpreadsheetReader()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.