PHP code example of lopatin96 / laravel-campaign

1. Go to this page and download the library: Download lopatin96/laravel-campaign 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/ */

    

lopatin96 / laravel-campaign example snippets


php artisan vendor:publish --tag="laravel-campaign-migrations"
 artisan migrate

php artisan vendor:publish --tag="laravel-campaign-config"

use Atin\LaravelCampaign\Traits\HasCampaign;

class User extends Authenticatable
{
    use HasCampaign;
   
    protected $casts = [
         'campaign_unsubscribed_at' => 'datetime',
    ];
}

php artisan make:mail TestMail

use Atin\LaravelMail\Mail\Mailable;

class TestMail extends Mailable
{
    public function build()
    {
         // Build email
    }
}

use Atin\LaravelCampaign\Campaigns\Campaign;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Builder;

class TestCampaign extends Campaign
{
    protected string $mailable = '\App\Mail\TestMail';
    
    protected function buildQuery(): Builder
    {
         return \App\Models\User::where(function($query) {
            $query->whereDate('users.trial_ends_at', '>=', now())
                ->whereDate('users.trial_ends_at', '<', now()->addDay());
        });
    }
}



return [
    'active_mails' => [
        '\App\Campaigns\TestCampaign' => 'daily',
    ]
];

use Atin\LaravelCampaign\Console\SendCampaignEmails;

class Kernel extends ConsoleKernel
{
    protected function schedule(Schedule $schedule): void
    {
        $schedule->call(new SendCampaignEmails())
            ->hourly();
    }

php artisan vendor:publish --tag="laravel-campaign-config"

php artisan vendor:publish --tag="laravel-campaign-views"

php artisan vendor:publish --tag="laravel-campaign-lang"

php artisan vendor:publish --tag="laravel-campaign-migrations"
app/Concole/Kernel.php