How to add custom class in Laravel 5

In this tutorial, I will show you how to add a custom PHP class in Laravel 5.x application. For example, Lets call our class Common.php. Create a directory called Mylibs in app directory along with your class, Ex: Common.php. Make sure to add the correct namespace to the class as for your directory structure, in this example it is App\Mylibs as our common.php file located at App\Mylibs\Common.php

How to add custom class in Laravel 5

Example Custom class in Laravel 5

Here is my final class :

Now, you can access this class using the namespace within your classes just like other Laravel classes.
use App\Mylibs\Common

That is it.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

DMCA.com Protection Status