kreait / laravel-firebase

A Laravel package for the Firebase PHP Admin SDK
https://github.com/kreait/firebase-php
MIT License
994 stars 163 forks source link

Firebase project [myproject] not configured. #70

Closed virenderscideas closed 3 years ago

virenderscideas commented 3 years ago

Hello,

I am getting this error "Firebase project [myproject] not configured." while sending a notification in laravel with FirebaseChannel. public function via($notifiable) { return [FirebaseChannel::class]; }

it's probably generated from this file but don't know what i did wrong.

vendor/kreait/laravel-firebase/src/FirebaseProjectManager.php:41

protected function configuration(string $name): array { $config = $this->app->config->get('firebase.projects.'.$name) ?? null; if (!$config) { throw new InvalidArgumentException("Firebase project [{$name}] not configured."); } return $config; }

jeromegamez commented 3 years ago

Hey @virenderscideas, FYI I moved this issue from the firebase-php repo here. How have you configured the package? Which versions of the kreait packages are you using (composer show | grep kreait)? On which PHP version? Is this something that worked before but stopped working?

adityaa-codes commented 3 years ago

i'm facing the same issue Below is the composer show image

adityaa-codes commented 3 years ago

what is the right way to configure firebase in laravel? all the tutorials and articles are outdated and there's no recent specific laravel based articles. Thanks in Advance

jeromegamez commented 3 years ago

Have you put a FIREBASE_CREDENTIALS=/path/to/your/service_account.json line in your .env file? (https://github.com/kreait/laravel-firebase#configuration)

adityaa-codes commented 3 years ago

Its in my project root directory image

i've tried this way too image

jeromegamez commented 3 years ago

Sorry for the late reply - have you resolved the issue in the meantime? If not, could you please share the full contents of config/firebase.php?

denzkiuy commented 3 years ago

I'm having the same issue, it's my first time trying firebase and this package. I have placed the service account json in the .env file as well. I haven't touched the firebase.php configuration.

jeromegamez commented 3 years ago

I just realized that FirebaseChannel seems to be a class from https://github.com/laravel-notification-channels/ - could this perhaps be an error that's triggered from there?

Either way, it would be nice if you could show me some reproducible code that I can use to test this - in my local tests, everything seems to work just fine, and I would be happy if it's a bug in the package, because then I can fix it 🤞

denzkiuy commented 3 years ago

In my case i didn't use FirebaseChannel, I'm still new to firebase so i just followed the documentation of the Firebase PHP Admin SDK

`use Kreait\Firebase\Messaging\CloudMessage; use Kreait\Firebase\Messaging\Notification;

    $topic = 'topic';
    $title = 'Title';
    $body = 'Body';

    $messaging = app('firebase.messaging');

    $notification = Notification::create($title, $body);

    $message = CloudMessage::withTarget('topic', $topic)
        ->withNotification($notification) // optional
        ->withData($data) // optional
    ;

    $messaging->send($message);`
denzkiuy commented 3 years ago

Also, I tried not putting the FIREBASE_CREDENTIALS into the .env file to find out what error it'll give me. And it's the same error.

jeromegamez commented 3 years ago

I just tried in my test-laravel project and I'm sorry I can't confirm the problem. What wonders me is that you get the error names myproject as a project - if no other configuration is present, the default project is referenced as app. 🤔

Which Laravel and PHP version are you using? What happens when, instead of app('firebase.messaging') you try

use Kreait\Laravel\Firebase\Facades\Firebase;

// ...

$messaging = Firebase::messaging();

?

Just to be sure, please share the output of these commands in your terminal:

$ php -v
$ composer show
denzkiuy commented 3 years ago

I think I found my mistake. I actually specified the project name in the env file FIREBASE_PROJECT thinking that this will only let me specify the "Name" of the firebase project. Looking at the firebase.php config file I think I realize how it works now.

Thank you so much @jeromegamez for the very quick response!!

jeromegamez commented 3 years ago

Glad I could help, I hope the package can serve you well from here on! 🌺

Prakort commented 2 years ago

I had the same issue but running php artisan config:cache fixed the issue.

jeromegamez commented 11 months ago

Yes, it's the project ID from credentials file

nehabvm23 commented 6 months ago

hii, I am having the same issue, i run the above mentioned commands also, but not worked..

liza-nt commented 5 months ago

adding FIREBASE_PROJECT in .env still did not work for me

jeromegamez commented 5 months ago

@liza-nt This issue is three years old 😅