Phpstorm에서 Laravel의 mailchimp 플러그인 사용하기
https://github.com/spatie/laravel-newsletter
이걸 쓰려고 했다.
설명대로 했는데 계속 Undefined class 또는, Non static method 라면서 철벽을 쳐댔다.
일단 설명대로 설치부터 해준다.
composer require spatie/laravel-newsletter
php artisan vendor:publish --provider="Spatie\Newsletter\NewsletterServiceProvider"
두번째의 경우는 했는데 config 파일이 생성되지 않았다.
.env 파일에 직접 추가하기로 했다.
MAILCHIMP_APIKEY=<YOUR_API_KEY>
MAILCHIMP_LIST_ID=<YOUR_LIST_ID>
config/newsletter.php 파일은 아래 내용을 복사하여 직접 추가했다.
return [ /* * The API key of a MailChimp account. You can find yours at * https://us10.admin.mailchimp.com/account/api-key-popup/. */ 'apiKey' => env('MAILCHIMP_APIKEY'), /* * The listName to use when no listName has been specified in a method. */ 'defaultListName' => 'subscribers', /* * Here you can define properties of the lists. */ 'lists' => [ /* * This key is used to identify this list. It can be used * as the listName parameter provided in the various methods. * * You can set it to any string you want and you can add * as many lists as you want. */ 'subscribers' => [ /* * A MailChimp list id. Check the MailChimp docs if you don't know * how to get this value: * http://kb.mailchimp.com/lists/managing-subscribers/find-your-list-id. */ 'id' => env('MAILCHIMP_LIST_ID'), ], ], /* * If you're having trouble with https connections, set this to false. */ 'ssl' => true, ];
문제는 여기부터였다.
Newsletter::subscribe("email@address.com"); 하면 된다는데 도무지 되질 않았다.
찾아보니 config/app.php 에 Provider와 Facade를 모두 추가 해줘야만 하는거였다.
'providers' => [
...
Illuminate\Auth\AuthServiceProvider::class, 'Spatie\Newsletter\NewsletterServiceProvider', ],
'aliases' => [
...
'App' => Illuminate\Support\Facades\App::class, 'Newsletter' => 'Spatie\Newsletter\NewsletterFacade', ],
여기까지 추가해주고, Controller 상단에는
use Newsletter;
이렇게,
Newsletter::subscribe($email);
if (Newsletter::lastActionSucceeded() === 1) {
$return = [
"status" => TRUE,
"message" => __("subscribe_success"),
];
} else {
$return = [
"status" => FALSE,
"message" => __("subscribe_failed") . " - " . Newsletter::getLastError(),
];
}
사용은 이렇게 했다.
해보니 작동은 하는데, 여전히 Phostorm 에서는 Undefined class 가 밑줄과 함께 넘실대고 있었다.
터미널에서 (또는 ctrl + shift + X 로 설정해 둔 command line support 에서)
$ php artisan ide_helper:generate
를 한번 해주고, Phpstorm에서 Invalidate Cache/Restart 를 한번 해줬더니 제대로 나온다.