DEV Community

Bhanu Pratap Singh
Bhanu Pratap Singh

Posted on

Laravel Create Custom Class

First we will create custom class file inside laravel project app/Classes If Classes folder doesn't exist inside app folder then create it manually.

coderuck-laravel-custom-class-1

Second step is to create your class file, I have created like SendSms.php inside your app/Classes folder.

Third step define your class code.

coderuck-laravel-custom-class-2

Finally you have created your custom class now how to access custom class method.?

Define use App\Classes\SendSms; on the top of your controller.Then only you can able to access custom class method.

coderuck-laravel-custom-class-3

@Other Reference

@Coderuck

Top comments (1)

Collapse
 
zubairmohsin33 profile image
Zubair Mohsin

Hi there, just noticed that env() function inside class.
Consider refactoring it to a configuration variable and then use config() to access that value.
By doing this, you can leverage configuration caching in production.