PHP code example of ylsideas / subscribable-notifications
1. Go to this page and download the library: Download ylsideas/subscribable-notifications library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ylsideas / subscribable-notifications example snippets
public class SubscriberServiceProvider
{
...
public function onUnsubscribeFromAllMailingLists()
{
return '\App\UnsubscribeHandler@handleUnsubscribing';
}
...
}
php
use YlsIdeas\SubscribableNotifications\Contracts\CanUnsubscribe;
class User implements CanUnsubscribe
{
use Notifiable;
public function unsubscribeLink(?string $mailingList = ''): string
{
return URL::signedRoute(
'sorry-to-see-you-go',
['subscriber' => $this, 'mailingList' => $mailingList],
now()->addDays(1)
);
}
}
php
use YlsIdeas\SubscribableNotifications\Contracts\AppliesToMailingList;
class Welcome extends Notification implements AppliesToMailingList
{
...
public function usesMailingList(): string
{
return 'weekly-updates';
}
...
}
php
public class SubscriberServiceProvider
{
...
public function onUnsubscribeFromMailingList()
{
return function ($user, $mailingList) {
$user->mailing_lists = $user->mailing_lists->put($mailingList, false);
$user->save();
};
}
...
}
php
public class SubscriberServiceProvider
{
...
public function onUnsubscribeFromAllMailingLists()
{
return function ($user) {
$user->unsubscribed_at = now();
$user->save();
};
}
...
}
php
public class SubscriberServiceProvider
{
...
public function onCompletion()
{
return function ($user, $mailingList) {
return view('confirmation')
->with('alert', 'You\'re not unsubscribed');
};
}
...
}
php
use YlsIdeas\SubscribableNotifications\Contracts\CheckNotifiableSubscriptionStatus;
class Welcome extends Notification implements CheckNotifiableSubscriptionStatus
{
...
public function checkMailSubscriptionStatus() : bool
{
return true;
}
...
}
php
public class SubscriberServiceProvider
{
...
public function onCheckSubscriptionStatusOfMailingList()
{
return function ($user, $mailingList) {
return $user->mailing_lists->get($mailingList, false);
};
}
public function onCheckSubscriptionStatusOfAllMailingLists()
{
return function ($user) {
return $user->unsubscribed_at === null;
};
}
...
}