How to automatically load custom classes in laravel 5.2?
巴扎黑
巴扎黑 2017-05-16 16:49:26
0
2
505

1. Define a class QrCode.php

under app\Libraires
<?php
/**
 * Created by PhpStorm.
 * User: AIMPER
 * Date: 2016/11/30
 * Time: 10:13
 */

namespace App\Libaries;
use Endroid\QrCode;
use Illuminate\Support\Facades\DB;

class QrCode{

    public static function generateQrCode($type = null, $id = null){
        $code = random_string(32,true);
        $create_date = time();
        $expires = 0;

        $qrcodeType = DB::table('qrcode_type')->where('id','=',$type)->select('code','params')-first();
        return $qrcodeType;

    }

}

2. Call the method of this class

...
use App\Libaries\QrCode;
class TestController extends Controller{
    public function index(){
        QrCode::generateQrCode(11,1);
    }
}

3. Error message

ReflectionException in Route.php line 286:
Class App\Libaries\QrCode does not exist

4. Solution attempt
I have used composer dump-autoload, but the class still cannot be loaded. How can I automatically load custom classes into the project?

巴扎黑
巴扎黑

reply all(2)
迷茫

Classes obtained through dependency injection in routing need to be registered with the container.

滿天的星座

Check the settings of the composer.json file in the project root directory.

"autoload": {
    "files":[
        "app/helpers.php"
    ],
    "psr-4": {
        "App\": "app/"
    }
},

And the error occurred during the route definition process. You need to check the settings of route.php

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template