Skip to content

Commit 130f5d7

Browse files
committed
added database migration and update readme
1 parent 8adfe8a commit 130f5d7

File tree

6 files changed

+95
-170
lines changed

6 files changed

+95
-170
lines changed

README.md

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
## Introduction
1111

12-
This is a package that stores and queues e-mails using a database table. Easily send e-mails using a cronjob or schedule e-mails that should be sent at a specific date and time.
12+
This is a package that stores and queues e-mails using a database table. Easily send e-mails using a cronjob and schedule e-mails that should be sent at a specific date and time.
1313
## Installation
1414

1515
First, require the package using composer.
@@ -24,16 +24,15 @@ If you're running Laravel 5.5 or later you may skip this step. Add the service p
2424
Buildcode\LaravelDatabaseEmails\LaravelDatabaseEmailsServiceProvider::class,
2525
```
2626

27-
Publish the configuration file.
27+
Publish the configuration files.
2828

2929
```bash
3030
$ php artisan vendor:publish --provider=Buildcode\\LaravelDatabaseEmails\\LaravelDatabaseEmailsServiceProvider
3131
```
3232

33-
Create the e-mails database table migration.
33+
Create the database table required for this package.
3434

3535
```bash
36-
$ php artisan email:table
3736
$ php artisan migrate
3837
```
3938

@@ -57,7 +56,7 @@ protected function schedule(Schedule $schedule)
5756
### Create An Email
5857

5958
```php
60-
Buildcode\LaravelDatabaseEmails\Email::compose()
59+
Email::compose()
6160
->label('welcome-mail-1.0')
6261
->recipient('john@doe.com')
6362
->subject('This is a test')
@@ -68,20 +67,53 @@ Buildcode\LaravelDatabaseEmails\Email::compose()
6867
->send();
6968
```
7069

70+
### Specify Recipients
71+
72+
```php
73+
$one = 'john@doe.com';
74+
$multiple = ['john@doe.com', 'jane@doe.com'];
75+
76+
Email::compose()->recipient($one);
77+
Email::compose()->recipient($multiple);
78+
79+
Email::compose()->cc($one);
80+
Email::compose()->cc($multiple);
81+
82+
Email::compose()->bcc($one);
83+
Email::compose()->bcc($multiple);
84+
```
85+
86+
### Mailables
87+
88+
You may also pass a mailable to the e-mail composer.
89+
90+
```php
91+
Email::compose()
92+
->mailable(new OrderShipped())
93+
->send();
94+
```
95+
96+
### Attachments
97+
98+
```php
99+
Email::compose()
100+
->attach('/path/to/file');
101+
```
102+
103+
Or for in-memory attachments...
104+
105+
```php
106+
Email::compose()
107+
->attachData('<p>Your order has shipped!</p>', 'order.html');
108+
```
109+
71110
### Schedule An Email
72111

73-
You may schedule an e-mail by calling `schedule` instead of `send` at the end of the chain. You must provide a Carbon instance or a strtotime valid date.
112+
You may schedule an e-mail by calling `later` instead of `send` at the end of the chain. You must provide a Carbon instance or a strtotime valid date.
74113

75114
```php
76-
Buildcode\LaravelDatabaseEmails\Email::compose()
77-
->label('welcome-mail-1.0')
78-
->recipient('john@doe.com')
79-
->subject('This is a test')
80-
->view('emails.welcome')
81-
->variables([
82-
'name' => 'John Doe',
83-
])
84-
->schedule('+2 hours');
115+
Email::compose()
116+
->later('+2 hours');
85117
```
86118

87119
### Manually Sending E-mails
@@ -115,8 +147,3 @@ If you wish to encrypt your e-mails, please enable the `encrypt` option in the c
115147
If you wish to send e-mails to a test address but don't necessarily want to use a service like mailtrap, please take a look at the `testing` configuration. This is turned on by default.
116148

117149
During the creation of an e-mail, the recipient will be replaced by the test e-mail. This is useful for local development or testing on a staging server.
118-
119-
## Todo
120-
121-
- Add support for attachments
122-
- Add support for Mailables

database/migrations/emails.stub renamed to database/migrations/2017_12_14_151403_create_emails_table.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Database\Migrations\Migration;
66

7-
class Create{{tableClassName}}Table extends Migration
7+
class CreateEmailsTable extends Migration
88
{
99
/**
1010
* Run the migrations.
@@ -13,7 +13,11 @@ class Create{{tableClassName}}Table extends Migration
1313
*/
1414
public function up()
1515
{
16-
Schema::create('{{table}}', function (Blueprint $table) {
16+
if (Schema::hasTable('emails')) {
17+
return;
18+
}
19+
20+
Schema::create('emails', function (Blueprint $table) {
1721
$table->increments('id');
1822
$table->string('label')->nullable();
1923
$table->binary('recipient');
@@ -44,6 +48,6 @@ public function up()
4448
*/
4549
public function down()
4650
{
47-
Schema::dropIfExists('{{table}}');
51+
//
4852
}
4953
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class AddAttachmentsToEmailsTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
if (Schema::hasColumn('emails', 'attachments')) {
17+
return;
18+
}
19+
20+
Schema::table('emails', function (Blueprint $table) {
21+
$table->binary('attachments')->after('body');
22+
});
23+
}
24+
25+
/**
26+
* Reverse the migrations.
27+
*
28+
* @return void
29+
*/
30+
public function down()
31+
{
32+
//
33+
}
34+
}

src/CreateEmailTableCommand.php

Lines changed: 0 additions & 111 deletions
This file was deleted.

src/LaravelDatabaseEmailsServiceProvider.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ class LaravelDatabaseEmailsServiceProvider extends ServiceProvider
1313
*/
1414
public function boot()
1515
{
16-
$dir = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR;
16+
$baseDir = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR;
17+
$configDir = $baseDir . 'config' . DIRECTORY_SEPARATOR;
18+
$migrationsDir = $baseDir . 'database' . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR;
1719

1820
$this->publishes([
19-
$dir . 'laravel-database-emails.php' => config_path('laravel-database-emails.php')
21+
$configDir . 'laravel-database-emails.php' => config_path('laravel-database-emails.php'),
2022
]);
23+
24+
$this->loadMigrationsFrom([$migrationsDir]);
2125
}
2226

2327
/**
@@ -28,7 +32,6 @@ public function boot()
2832
public function register()
2933
{
3034
$this->commands([
31-
CreateEmailTableCommand::class,
3235
SendEmailsCommand::class,
3336
RetryFailedEmailsCommand::class,
3437
]);

tests/TestCase.php

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Tests;
44

55
use Buildcode\LaravelDatabaseEmails\Email;
6-
use Illuminate\Database\Schema\Blueprint;
76
use Eloquent;
87

98
class Testcase extends \Orchestra\Testbench\TestCase
@@ -26,42 +25,11 @@ function () {
2625
},
2726
];
2827

29-
$this->createSchema();
28+
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
3029

3130
view()->addNamespace('tests', __DIR__ . '/views');
3231
}
3332

34-
/**
35-
* Setup the database schema.
36-
*
37-
* @return void
38-
*/
39-
public function createSchema()
40-
{
41-
$this->schema()->create('emails', function (Blueprint $table) {
42-
$table->increments('id');
43-
$table->string('label')->nullable();
44-
$table->binary('recipient');
45-
$table->binary('cc')->nullable();
46-
$table->binary('bcc')->nullable();
47-
$table->binary('subject');
48-
$table->string('view', 255);
49-
$table->binary('variables')->nullable();
50-
$table->binary('body');
51-
$table->binary('attachments');
52-
$table->integer('attempts')->default(0);
53-
$table->boolean('sending')->default(0);
54-
$table->boolean('failed')->default(0);
55-
$table->text('error')->nullable();
56-
$table->boolean('encrypted')->default(0);
57-
$table->timestamp('scheduled_at')->nullable();
58-
$table->timestamp('sent_at')->nullable();
59-
$table->timestamp('delivered_at')->nullable();
60-
$table->timestamps();
61-
$table->softDeletes();
62-
});
63-
}
64-
6533
/**
6634
* Get a database connection instance.
6735
*

0 commit comments

Comments
 (0)