Posted on Updated on - Arjun

How to add custom class in Laravel 5

In this tutorial I will show you how to add custom class in Laravel 5. For example my class name is Common.php. Now create a directory called Mylibs in app directory(app/Mylibs). Place your custom class in created directory and just make sure to add the correct namespace to the class as for your directory structure, in my example it is App\Mylibs.

How to add 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.


I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets.

  • Gerald Schmidt

    Thanks for the tutorial! You have forgotten your “;” for the return statement in the common class 🙂


    • Thanks Gerald, Updated post!

  • Jonathan Duran

    thank you bro

  • Christian David Arevalo Quijan

    I’m not sure but I had to call the function different
    Instead of this:

    Do this:


    • ‘->’ missing there, Thanks updated code. Protection Status