jeudi 12 octobre 2017

Laravel cannot use custom App PHP files in controllers

In my controller I am trying to use a PHP file that is located within the App directory.

My controller looks like

    namespace App\Http\Controllers;

    use Illuminate\Http\Request;
    use App\MyClass\API;
    public function getservices(Request $request)
    {
        $sourcename = request('sName');
        $password = request('password');
        $siteID = request('siteID');

       // initialize default credentials
        $creds = new SourceCredentials($sourcename, $password, 
        array($siteID));

The SourceCredentials function is within the API class, located in App\MyClass\API, this is API.PHP

namespace App\MyClass;

class SourceCredentials
{
    public $SourceName;
    public $Password;
    public $SiteIDs;
    //some other stuffs

When I make a POST request to the controller using my routes, I get this error -

Class 'App\Http\Controllers\SourceCredentials' not found

Am I making some mistakes here? I have named the namespace correctly for the API.PHP and I am using that namespace in my controller. Please help.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire