Where to put custom/new class file in Laravel?

纵然是瞬间 提交于 2020-05-13 07:08:51

问题


I have PHP example on how to use Yelp Fusion API. It uses OAuth.php file with several classes. In main example it is imported with

require_once('lib/OAuth.php');

Can I do the same in Laravel?

Or I'd better provide namespace for OAuth.php file and put it somewhere on the tree? Where to put it?


回答1:


I suggest your to make a new directory inside app and call it like "Classes" and store your OAuth.php as "/app/Classes/OAuth.php". Don't forget to put a namespace App\Classes; to top of this file.

Due to having several classes inside your file I suggest to rewrite this a bit and separate each class to file




回答2:


You can use Yelp Fusion API with any other OAuth implementation. Here are OAuth packages for composer: https://packagist.org/search/?q=oauth

Using packages instead of custom PHP files would help to keep project clean.

If you still need to add any custom PHP files just create a directory within /app like "Libraries" or "Helpers" or what fits better to your content.

Directories and files within /app directory loaded automatically by Composer.



来源:https://stackoverflow.com/questions/43277015/where-to-put-custom-new-class-file-in-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!