问题
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