Packaging custom classes in Laravel 5

Jude Niroshan

I'm a newbie to Laravel framework. I have created a custom class called UploadUtils.php and placed it inside the App\Classes.

<?php

namespace App\Classes;

class UploadVideoUtils{
    public static function checking(){
        echo "FRom the func";
    }
}

I was able to use that class in my controller like below code.

use App\Classes\UploadVideoUtils;

class Test extends Controller{

public function testing(){
        echo "Testing ";

        $some1 = new UploadVideoUtils();
        $some1->checking();

        echo " done ";
     }
}

I don't want to put all of classes under App\Classes. Instead I want to package them and I want to maintain nice code base. So, I created a new folder like App\Classes\Common and put my UploadUtils.php class and try to call it from the controller. But it magically copy the UploadUtils.php file in App\Classes. And it doesn't use the file in App\Classes\Common.

How to have proper packaging (Directory structure) for my custom classes?

Samuel Cloete

Make sure you have deleted the file in App\Classes. Then in your controller use App\Classes\Common\UploadUtils. Then run composer dumpautoload to regenerate the autoloader.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related