Getting Started
Package Installation
Package installation is deprecated
As of Version 2, Sendyak can be installed as a stand-alone application (i.e. including everything you need to run SendYak), or as a package inside an existing Laravel application.
This page covers the Package installation. If you want to install SendYak as a stand-alone application, then head over to the Installation guide.
Requirements
- Laravel ≥ 8
- PHP ≥ 7.3
- MySQL (≥ 5.7) or PostgreSQL (≥ 9.4)
Installation
To install SendYak as a package from your command line, run the following command:
1composer require cweagans/sendyak-core
Alternatively, you can add the following to your composer.json
file:
1"cweagans/sendyak-core": "^2.0"
and then run composer update
to install it.
Publish Assets
Run the following command to publish SendYak’s assets:
1php artisan vendor:publish --provider=Sendyak\\Base\\SendyakBaseServiceProvider
Resolvers & Routes
SendYak’s functionality is linked to your application through the use of the Sendyak
facade. The following sections will detail how to use this facade to get SendYak up and running inside your application.
Please read all sections and decide on the relevancy to your use case. Some sections are marked as Required, and will need to be completed for a successful integration with SendYak. Other sections are marked as Optional and may or may not be required for your own use case.
Workspace Resolver (Required)
In order to support multi-tenancy, SendYak requires a “Workspace ID” for the session. Even if your host application does not use multi-tenancy, you will still need to provide a “dummy” integer.
The Workspace ID will be used in both web and API sessions and will be stored to the database in the workspace_id
column of tables like sendyak_campaigns
, sendyak_subscribers
, etc.
Multi-tenancy is optional. If your application is not multi-tenant, or you do not wish to use SendYak in a multi-tenant way, you can provide a hardcoded integer value of your choice to the resolver.
Registering the Workspace Resolver
Inside the boot
method of a service provider class, provide a closure to the Sendyak\Base\Facades\Sendyak::setCurrentWorkspaceIdResolver()
method that resolves a workspace ID.
The return value of your closure must be an integer value and must not be null.
As an example:
1<?php
2declare(strict_types=1);
3
4namespace App\Providers;
5
6use Illuminate\Support\ServiceProvider;
7use Sendyak\Base\Facades\Sendyak;
8
9class AppServiceProvider extends ServiceProvider
10{
11 // …
12 public function boot(): void
13 {
14 Sendyak::setCurrentWorkspaceIdResolver(function () {
15 return 1;
16 });
17 }
18}
Routes
There are 4 route definitions that can be defined:
- Web Routes (required)
- Public Web Routes (required)
- Public API Routes (required)
- API Routes (optional)
The following routes can all be placed inside a route group, in which case any group prefixes, names, middlewares, etc, will also be applied. However, note that SendYak’s route names already include sendyak.
.
Web Routes (Required)
To access SendYak’s application resources (e.g. Campaigns, Subscribers, Templates, Messages etc) from the browser, you must register SendYak’s web routes.
Inside a routes file, call the Sendyak\Base\Facades\Sendyak::webRoutes()
method.
These routes include features like subscriber management and campaign sending, and therefore should not be exposed without some means of authentication.
1// routes/web.php
2Route::middleware(['auth'])->prefix('sendyak')->group(function () {
3 Sendyak::webRoutes();
4});
Public Web Routes (Required)
To provide access to features such as unsubscribing from a mailing list and viewing subscriber emails in the browser, you must register SendYak’s public web routes.
Inside a routes file, call the Sendyak\Base\Facades\Sendyak::publicWebRoutes()
method.
These routes include publically accessible features such as unsubscribing from a mailing list, and therefore should not be guarded by authentication.
1// routes/web.php
2Sendyak::publicWebRoutes();
Public API Routes (Required)
To handle campaign tracking (i.e. webhooks from your email service provider), you must register SendYak’s public API routes.
Inside a routes file, call the Sendyak\Base\Facades\Sendyak::publicApiRoutes()
method.
These routes include webhooks that are needed to track campaigns inside SendYak, and must be accessible to your email service.
1// routes/api.php
2Sendyak::publicApiRoutes();
Set Up SendYak API Routes (Optional)
If you wish to provide access to SendYak’s API, then you must register SendYak’s API routes.
Inside a routes file, call the Sendyak\Base\Facades\Sendyak::apiRoutes()
method.
These routes include features like subscriber and campaign management, and should not be exposed to the internet without some means of authentication.
1// routes/api.php
2Route::middleware(['auth:api'])->group(function() {
3 Sendyak::apiRoutes();
4});
Set Up Sidebar HTML Content Resolver (Optional)
Optionally, you can provide content to the sidebar navigation in SendYak. This allows you to inject new menu items that can link to resources you build yourself. This is helpful for providing access to functionality like user management inside SendYak.
Registering Sidebar HTML Resolver
Inside the boot
method of a service provider class, provide a closure to the Sendyak\Base\Facades\Sendyak::setSidebarHtmlContentResolver()
method.
The return value of your closure must be a string value or null. You should ideally provide HTML, as it will be rendered directly into the view as provided.
As an example:
1 public function boot(): void
2 {
3 Sendyak::setSidebarHtmlContentResolver(function () {
4 return view('layouts.sidebar.manageUsersMenuItem')->render();
5 });
6 }
Set Up Header HTML Content Resolver (Optional)
You can optionally provide content to the header in SendYak. This allows you to inject resources that you build yourself. This is helpful for providing functionality like user profile management or workspace switchers inside SendYak.
Registering Header HTML Resolver
Inside the boot
method of a service provider class, provide a closure to the Sendyak\Base\Facades\Sendyak::setHeaderHtmlContentResolver()
method.
The return value of your closure must be a string value or null. You should ideally provide HTML, as it will be rendered directly into the view as provided.
As an example:
1 public function boot(): void
2 {
3 Sendyak::setHeaderHtmlContentResolver(function () {
4 return view('layouts.header.userManagementHeader')->render();
5 });
6 }
Further Examples
To see an example of SendYak used as a fully multi-tenant application, please see our own host application, which takes advantage of all the integration features available in the SendYak package.
In particular, see the App\Providers\AppServiceProvider
class for registering resolvers, and see the routes/web.php
and routes/api.php
files for registering routes.