Django102
Django102

Reputation: 543

Class 'Darksky\Darksky' not found in Laravel using the Darksky Weather API?

Using the Laravel Darksky API

I added the service provider to the providers array in config/app.php

Naughtonium\LaravelDarkSky\LaravelDarkSkyServiceProvider::class

and registered a facade accessor to config/app.php aliases array

'DarkSky' => \Naughtonium\LaravelDarkSky\Facades\DarkSky::class

So I called

use Darksky\Darksky;

Route::get('/', function () {
    DarkSky::location(90, 71)->get();
    return view('welcome');
});

But I get this error,

Class 'Darksky\Darksky' not found

What is wrong?

Upvotes: 0

Views: 126

Answers (1)

Jonathon
Jonathon

Reputation: 16323

When you add a facade to the aliases array, in this case:

'DarkSky' => \Naughtonium\LaravelDarkSky\Facades\DarkSky::class

that will make a facade available to use in the root namespace. You're trying to access it as if it was available in the DarkSky namespace.

use DarkSky\DarkSky;

You should change this line to:

use DarkSky;

or alternatively, you can use the facade directly instead of its root alias by changing it to:

use Naughtonium\LaravelDarkSky\Facades\DarkSky;

Upvotes: 2

Related Questions