Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel use external class

I'm new on Laravel and need some help. Actually I use 5.3 Laravel version. I need to use, in Laravel, external company framework (call it F for simplicity). This framework is some like process manager. Actually, for integrate it with laravel I put it in laravel/public folder, this way I can use laravel and F's pages in same domain. In laravel I need to access to some F functionality which is all collect in class FFramework\Facade\FInterface; Then I want to access to this class from laravel controller FController. But when I run code I get Class Not Found Exception.

This is folder structure:

  • laravel
    • app
      • http
        • controllers
          • FController.php
  • public
    • css
    • js
    • index.php
      • fframework
        • facade
          • FInterface.php
        • index.php

This is code example:

FController.php

<?php
  namespace App\Http\Controllers;

  use FFramework\facade\FInterface;

  class FController extends Controller {

      public function getSimpleDAta() {
          $f = new FInterface();
          return $f->getSimpleData();
    }
  }

FInterface.php

<?php
  namespace FFramework\facade;

  use some\internal\function;
  
  class FInterface {

      public function getSimpleDAta() {
          $simpleData = ...omg so much computation :) ...
          return $simpleData;
    }
  }
  

Exception that I get:

Class 'FFramework\facade\FInterface' not found

Additional Information

I use standard LAMP configuration PHP version is last 5.6 stable version

Question

How can I use FInterface from Laravel controller leaving FFramework in public folder?

like image 209
Maksym Bodnar Avatar asked Feb 20 '26 01:02

Maksym Bodnar


1 Answers

You need to update the autoload section of your composer.json file to tell your project where to look for files in the FFramework namespace.

"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\\": "app/"
        "FFramework\\": "public/fframework"
    }
},
like image 192
patricus Avatar answered Feb 21 '26 17:02

patricus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!