Home
Softono
s

spatie

Professional software vendor delivering innovative solutions on the Softono platform. Specialized in both open-source and proprietary software development.

Total Products
11

Software by spatie

freek.dev
Open Source

freek.dev

[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/freekdev.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/freek.dev) We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). ## Blog Posts API The site exposes a REST API at `/api/posts` for programmatic blog post management (e.g. by an AI tool). It is protected by Sanctum token authentication and restricted to admin users. ### Authentication All requests require a Bearer token in the `Authorization` header. ``` Authorization: Bearer <token> ``` To create a token, run this in tinker: ```php $user = User::where('admin', true)->first(); $token = $user->createToken('ai-tool'); $token->plainTextToken; // save this, it's only shown once ``` ### Endpoints #### List posts ``` GET /api/posts ``` Query parameters (all optional): - `published` (0 or 1): filter by published status - `original_content` (0 or 1): filter by original content - `tag` (string): filter by tag name - `search` (string): search posts by title Returns paginated results. #### Get a post ``` GET /api/posts/{id} ``` #### Create a post ``` POST /api/posts ``` Body (JSON): - `title` (string, required) - `text` (string, required, markdown) - `publish_date` (ISO 8601 date, nullable) - `published` (boolean, default false) - `original_content` (boolean, default false) - `external_url` (URL string, nullable) - `tags` (array of strings) - `send_automated_tweet` (boolean, default false) - `author_twitter_handle` (string, nullable) - `series_slug` (string, nullable) Returns 201 with the created post. #### Update a post ``` PUT /api/posts/{id} ``` Same fields as create, all optional. Only send fields you want to change. #### Delete a post ``` DELETE /api/posts/{id} ``` Returns 204 No Content. ### Response format All responses are wrapped in a `data` key: ```json { "data": { "id": 1, "title": "...", "slug": "...", "text": "...", "html": "...", "publish_date": "2026-03-02T14:00:00+00:00", "published": true, "original_content": false, "external_url": null, "series_slug": null, "author_twitter_handle": null, "send_automated_tweet": false, "tags": ["laravel", "php"], "url": "https://freek.dev/1-post-slug", "preview_url": "https://freek.dev/1-post-slug?preview_secret=abc123", "created_at": "2026-03-02T12:00:00+00:00", "updated_at": "2026-03-02T12:00:00+00:00" } } ``` ## Contributing Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details. ## Security If you've found a bug regarding security please mail [[email protected]](mailto:[email protected]) instead of using the issue tracker. ## Postcardware You're free to use this code (it's [MIT-licensed](LICENSE.md)). If you use it to set up your own blog we would highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium. All postcards are published [on our website](https://spatie.be/en/opensource/postcards). ## Credits - [Freek Van der Herten](https://github.com/freekmurze) - [All Contributors](../../contributors) ## License The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

CMS & Blogging Traditional CMS
648 Github Stars
package-skeleton-laravel
Open Source

package-skeleton-laravel

# :package_description [![Latest Version on Packagist](https://img.shields.io/packagist/v/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug) [![GitHub Tests Action Status](https://github.com/spatie/package-skeleton-laravel/actions/workflows/run-tests.yml/badge.svg)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3Arun-tests+branch%3Amain) [![GitHub Code Style Action Status](https://github.com/spatie/package-skeleton-laravel/actions/workflows/fix-php-code-style-issues.yml/badge.svg)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain) [![Total Downloads](https://img.shields.io/packagist/dt/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug) <!--delete--> --- This repo can be used to scaffold a Laravel package. Follow these steps to get started: 1. Press the "Use this template" button at the top of this repo to create a new repo with the contents of this skeleton. 2. Run "php ./configure.php" to run a script that will replace all placeholders throughout all the files. 3. Have fun creating your package. 4. If you need help creating a package, consider picking up our <a href="https://laravelpackage.training">Laravel Package Training</a> video course. --- <!--/delete--> This is where your description should go. Limit it to a paragraph or two. Consider adding a small example. ## Support us [<img src="https://github-ads.s3.eu-central-1.amazonaws.com/:package_name.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/:package_name) We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). ## Installation You can install the package via composer: ```bash composer require :vendor_slug/:package_slug ``` You can publish and run the migrations with: ```bash php artisan vendor:publish --tag=":package_slug-migrations" php artisan migrate ``` You can publish the config file with: ```bash php artisan vendor:publish --tag=":package_slug-config" ``` This is the contents of the published config file: ```php return [ ]; ``` Optionally, you can publish the views using ```bash php artisan vendor:publish --tag=":package_slug-views" ``` ## Usage ```php $:variable = new VendorName\Skeleton(); echo $:variable->echoPhrase('Hello, VendorName!'); ``` ## Testing ```bash composer test ``` ## Changelog Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. ## Contributing Please see [CONTRIBUTING](CONTRIBUTING.md) for details. ## Security Vulnerabilities Please review [our security policy](../../security/policy) on how to report security vulnerabilities. ## Credits - [:author_name](https://github.com/:author_username) - [All Contributors](../../contributors) ## License The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Developer Tools Package Managers
2.4K Github Stars
laravel-sitemap
Open Source

laravel-sitemap

<div align="left"> <a href="https://spatie.be/open-source?utm_source=github&utm_medium=banner&utm_campaign=laravel-sitemap"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://spatie.be/packages/header/laravel-sitemap/html/dark.webp"> <img alt="Logo for laravel-sitemap" src="https://spatie.be/packages/header/laravel-sitemap/html/light.webp"> </picture> </a> <h1>Generate sitemaps with ease</h1> [![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-sitemap.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-sitemap) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) [![Test Status](https://github.com/spatie/laravel-sitemap/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-sitemap/actions/workflows/run-tests.yml) [![Code Style Status](https://github.com/spatie/laravel-sitemap/actions/workflows/fix-php-code-style-issues.yml/badge.svg)](https://github.com/spatie/laravel-sitemap/actions/workflows/fix-php-code-style-issues.yml) [![PHPStan](https://github.com/spatie/laravel-sitemap/actions/workflows/phpstan.yml/badge.svg)](https://github.com/spatie/laravel-sitemap/actions/workflows/phpstan.yml) [![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-sitemap.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-sitemap) </div> This package can generate a sitemap without you having to add URLs to it manually. This works by crawling your entire site. ```php use Spatie\Sitemap\SitemapGenerator; SitemapGenerator::create('https://example.com')->writeToFile($path); ``` You can also create your sitemap manually: ```php use Carbon\Carbon; use Spatie\Sitemap\Sitemap; use Spatie\Sitemap\Tags\Url; Sitemap::create() ->add(Url::create('/home') ->setLastModificationDate(Carbon::yesterday())) ->add(...) ->writeToFile($path); ``` Or you can have the best of both worlds by generating a sitemap and then adding more links to it: ```php use Spatie\Sitemap\SitemapGenerator; use Spatie\Sitemap\Tags\Url; SitemapGenerator::create('https://example.com') ->getSitemap() ->add(Url::create('/extra-page') ->setLastModificationDate(Carbon::yesterday())) ->add(...) ->writeToFile($path); ``` You can also add your models directly by implementing the `Sitemapable` interface. ```php use Spatie\Sitemap\Contracts\Sitemapable; use Spatie\Sitemap\Tags\Url; class Post extends Model implements Sitemapable { public function toSitemapTag(): Url | string | array { return route('blog.post.show', $this); } } ``` ## Support us [<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-sitemap.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-sitemap) We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). ## Documentation All documentation is available [on our documentation site](https://spatie.be/docs/laravel-sitemap). ## Testing ```bash composer test ``` ## Changelog Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. ## Contributing Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details. ## Security If you've found a bug regarding security please mail [[email protected]](mailto:[email protected]) instead of using the issue tracker. ## Credits - [Freek Van der Herten](https://github.com/freekmurze) - [All Contributors](../../contributors) ## License The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

WordPress Themes & Plugins SEO Tools
2.6K Github Stars
schema-org
Open Source

schema-org

<div align="left"> <a href="https://spatie.be/open-source?utm_source=github&utm_medium=banner&utm_campaign=schema-org"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://spatie.be/packages/header/schema-org/html/dark.webp"> <img alt="Logo for schema-org" src="https://spatie.be/packages/header/schema-org/html/light.webp"> </picture> </a> <h1>A Fluent Builder For Schema.org Types And ld+json Generator</h1> [![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/schema-org.svg?style=flat-square)](https://packagist.org/packages/spatie/schema-org) [![MIT License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) [![Total Downloads](https://img.shields.io/packagist/dt/spatie/schema-org.svg?style=flat-square)](https://packagist.org/packages/spatie/schema-org) </div> `spatie/schema-org` provides a fluent builder for **all** Schema.org types and their properties. The code in `src` is generated from Schema.org's [JSON-LD standards file](https://raw.githubusercontent.com/schemaorg/schemaorg/main/data/releases/13.0/schemaorg-all-https.jsonld), so it provides objects and methods for the entire core vocabulary. The classes and methods are also fully documented as a quick reference. ```php use Spatie\SchemaOrg\Schema; $localBusiness = Schema::localBusiness() ->name('Spatie') ->email('[email protected]') ->contactPoint(Schema::contactPoint()->areaServed('Worldwide')); echo $localBusiness->toScript(); ``` ```html <script type="application/ld+json"> { "@context": "https:\/\/schema.org", "@type": "LocalBusiness", "name": "Spatie", "email": "[email protected]", "contactPoint": { "@type": "ContactPoint", "areaServed": "Worldwide" } } </script> ``` ## Support us [<img src="https://github-ads.s3.eu-central-1.amazonaws.com/schema-org.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/schema-org) We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). ## Installation You can install the package via composer: ``` bash composer require spatie/schema-org ``` ## Usage All types can be instantiated through the `Spatie\SchemaOrg\Schema` factory class, or with the `new` keyword. ``` php $localBusiness = Schema::localBusiness()->name('Spatie'); // Is equivalent to: $localBusiness = new LocalBusiness(); $localBusiness->name('Spatie'); ``` > *All types also accept arrays of the expected data type, for example `sameAs` accepts a string or an array of strings.* All types also implement the SPL's `ArrayAccess` for accessing the properties via array notation: ```php $anotherLocalBusiness = new LocalBusiness(); var_dump(isset($anotherLocalBusiness['name'])); // => false $anotherLocalBusiness['name'] = 'Spatie'; var_dump(isset($anotherLocalBusiness['name'])); // => true var_dump($anotherLocalBusiness['name']); // => 'Spatie' unset($anotherLocalBusiness['name']); var_dump(isset($anotherLocalBusiness['name'])); // => false ``` Types can be converted to an array or rendered to a script. ```php $localBusiness->toArray(); echo $localBusiness->toScript(); echo $localBusiness; // Same output as `toScript()` ``` Additionally, all types can be converted to a plain JSON string by just calling `json_encode()` with your object: ```php echo json_encode($localBusiness); ``` I recommend double checking your structured data with [Google's structured data testing tool](https://search.google.com/structured-data/testing-tool). ### Enumerations As of v1.6.0, all [Enumeration](https://schema.org/Enumeration) child types are available as classes with constants. ```php Schema::book()->bookFormat(Spatie\SchemaOrg\BookFormatType::Hardcover); ``` There's no full API documentation for types and properties. You can refer to [the source](https://github.com/spatie/schema-org/tree/master/src) or to [the schema.org website](https://schema.org). If you don't want to break the chain of a large schema object, you can use the `if` method to conditionally modify the schema. ```php use Spatie\SchemaOrg\LocalBusiness; use Spatie\SchemaOrg\Schema; $business = ['name' => 'Spatie']; $localBusiness = Schema::localBusiness() ->name($business['name']) ->if(isset($business['email']), function (LocalBusiness $schema) use ($business) { $schema->email($business['email']); }); ``` ### Identifier As of v2.6.0 the `identifier` key is replaced by `@id` for simple string identifiers. This is due to the definition for the `ld+json` syntax. > All schema.org syntaxes already have built-in representation for URIs and URLs, e.g. in Microdata 'itemid', in RDFa 1.1, 'resource', **in JSON-LD, '@id'.** > > &mdash; [schema.org/docs](https://schema.org/docs/datamodel.html#identifierBg) // [PR#102](https://github.com/spatie/schema-org/pull/102) // [PR#157](https://github.com/spatie/schema-org/pull/157) ### Advanced Usage If you'd need to set a custom property, you can use the `setProperty` method. ```php $localBusiness->setProperty('foo', 'bar'); ``` If you'd need to retrieve a property, you can use the `getProperty` method. You can optionally pass in a second parameter to provide a default value. ```php $localBusiness->getProperty('name'); // 'Spatie' $localBusiness->getProperty('bar'); // null $localBusiness->getProperty('bar', 'baz'); // 'baz' ``` All properties can be retrieved as an array with the `getProperties` method. ```php $localBusiness->getProperties(); // ['name' => 'Spatie', ...] ``` Multiple properties can be set at once using the `addProperties` method. ```php $localBusiness->addProperties(['name' => 'value', 'foo' => 'bar']); ``` Context and type can be retrieved with the `getContext` and `getType` methods. ```php $localBusiness->getContext(); // 'https://schema.org' $localBusiness->getType(); // 'LocalBusiness' ``` ### Graph - multiple items The Graph has a lot of methods and utilities - the type-safe and simplest way is to use the overloaded methods of the `Spatie\SchemaOrg\Schema` class itself. These methods will get an already created or new instance of the requested schema. ```php $graph = new Graph(); // Create a product and prelink organization $graph ->product() ->name('My cool Product') ->brand($graph->organization()); // Hide the organization from the created script tag $graph->hide(\Spatie\SchemaOrg\Organization::class); // Somewhere else fill out the organization $graph ->organization() ->name('My awesome Company'); // Render graph to script tag echo $graph; ``` With these tools the graph is a collection of all available schemas, can link these schemas with each other and prevent helper schemas from being rendered in the script-tag. ### Graph Node identifiers Sometimes you have to keep track of multiple Graph nodes of the same type - for example multiple `Person` nodes for different people in your Organization. To do so you are able to use node identifiers on your graph instance. If you don't provide an identifier a reserved keyword `default` identifier will be used. ```php use Spatie\SchemaOrg\Graph; use Spatie\SchemaOrg\Person; $graph = new Graph(); // add a Person using chaining $graph->person('freekmurze') ->givenName('Freek') ->familyName('Van der Herten') ->alternateName('freekmurze'); // add a Person using closure $graph->person('sebastiandedeyne', function(Person $sebastian, Graph $graph): void { $sebastian ->givenName('Sebastian') ->familyName('De Deyne') ->alternateName('sebastiandedeyne'); }); // add a person using closure and second call with same identifier $graph->person( 'gummibeer', fn(Person $gummibeer) => $gummibeer->alternateName('gummibeer') ); $graph->person('gummibeer') ->givenName('Tom') ->familyName('Witkowski'); $graph->person('random')->name('Random Person'); // hide the random person from Graph $graph->hide(Person::class, 'random'); echo json_encode($graph); ``` ```json { "@context":"https:\/\/schema.org", "@graph":[ { "@type":"Person", "givenName":"Freek", "familyName":"Van der Herten", "alternateName":"freekmurze" }, { "@type":"Person", "givenName":"Sebastian", "familyName":"De Deyne", "alternateName":"sebastiandedeyne" }, { "@type":"Person", "alternateName":"gummibeer", "givenName":"Tom", "familyName":"Witkowski" } ] } ``` ### Multi Typed Entities Schema.org allows [multi typed entities](https://github.com/schemaorg/schemaorg/wiki/How-to-use-Multi-Typed-Entities-or-MTEs) - to use them with this package you can use the `MultiTypedEntity` class - which works similar to the graph. ```php $mte = new MultiTypedEntity(); $mte->hotelRoom()->name('The Presidential Suite'); $mte->product()->offers( Schema::offer() ->name('One Night') ->price(100000.00) ->priceCurrency('USD') ); $mte->product(function (Product $product) { $product->aggregateRating( Schema::aggregateRating() ->bestRating(5) ->worstRating(4) ); }); echo json_encode($mte); ``` ```json { "@context":"https:\/\/schema.org", "@type":[ "HotelRoom", "Product" ], "name":"The Presidential Suite", "offers":{ "@type":"Offer", "name":"One Night", "price":100000, "priceCurrency":"USD" }, "aggregateRating":{ "@type":"AggregateRating", "bestRating":5, "worstRating":4 } } ``` There isn't a real rule in place how the properties are merged. It only uses `array_merge()` behind the scenes. So you should avoid defining the same property on different types in the MTE or be sure that all properties hold the same value that it's not important which property is used at the end. ## Known Issues - The `Float` type isn't available since it's a reserved keyword in PHP - The `Physician` type isn't available since it extends a type from the `health` extension spec ## Changelog Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. ## Testing ``` bash $ composer test ``` ## Contributing Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details. ## Security If you've found a bug regarding security please mail [[email protected]](mailto:[email protected]) instead of using the issue tracker. ## Postcardware You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium. We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards). ## Credits - [Sebastian De Deyne](https://github.com/sebastiandedeyne) - [Tom Witkowski](https://github.com/Gummibeer) - [All Contributors](../../contributors) ## License The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Web Components & Widgets SEO Tools
1.5K Github Stars
laravel-referer
Open Source

laravel-referer

# Remember a visitor's original referer [![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-referer.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-referer) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) [![run-tests](https://github.com/spatie/laravel-referer/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-referer/actions/workflows/run-tests.yml) [![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-referer.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-referer) Remember a visitor's original referer in session. The referer is (highest priority first): - The `utm_source` query parameter - The domain from the request's `Referer` header if there's an external host in the URL - Empty ## Support us [<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-referer.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-referer) We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). ## Installation You can install the package via composer: ``` bash composer require spatie/laravel-referer ``` The package will automatically register itself in Laravel 5.5. In Laravel 5.4. you'll manually need to register the `Spatie\Referer\RefererServiceProvider` service provider in `config/app.php`. You can publish the config file with: ``` php artisan vendor:publish --provider="Spatie\Referer\RefererServiceProvider" ``` Publishing the config file is necessary if you want to change the key in which the referer is stored in the session or if you want to disable a referer source. ```php return [ /* * The key that will be used to remember the referer in the session. */ 'session_key' => 'referer', /* * The sources used to determine the referer. */ 'sources' => [ Spatie\Referer\Sources\UtmSource::class, Spatie\Referer\Sources\RequestHeader::class, ], ]; ``` ## Usage To capture the referer, all you need to do is add the `Spatie\Referer\CaptureReferer` middleware to your middleware stack. In most configuration's, you'll only want to capture the referer in "web" requests, so it makes sense to register it in the `web` stack. Make sure it comes **after** Laravel's `StartSession` middleware! ```php // app/Http/Kernel.php protected $middlewareGroups = [ 'web' => [ // ... \Illuminate\Session\Middleware\StartSession::class, // ... \Spatie\Referer\CaptureReferer::class, // ... ], // ... ]; ``` The easiest way to retrieve the referer is by just resolving it out of the container: ```php use Spatie\Referer\Referer; $referer = app(Referer::class)->get(); // 'google.com' ``` Or you could opt to use Laravel's automatic facades: ```php use Facades\Spatie\Referer\Referer; $referer = Referer::get(); // 'google.com' ``` The captured referer is (from high to low priority): - The `utm_source` query parameter, or: - The domain from the request's `Referer` header if there's an external host in the URL, or: - Empty An empty referer will never overwrite an exisiting referer. So if a visitor comes from google.com and visits a few pages on your site, those pages won't affect the referer since local hosts are ignored. ### Forgetting or manually setting the referer The `Referer` class provides dedicated methods to forget, or manually set the referer. ```php use Facades\Spatie\Referer\Referer; Referer::put('google.com'); Referer::get(); // 'google.com' Referer::forget(); Referer::get(); // '' ``` ### Changing the way the referer is determined The referer is determined by doing checks on various sources, which are defined in the configuration. ```php return [ // ... 'sources' => [ Spatie\Referer\Sources\UtmSource::class, Spatie\Referer\Sources\RequestHeader::class, ], ]; ``` A source implements the `Source` interface, and requires one method, `getReferer`. If a source is able to determine a referer, other sources will be ignored. In other words, the `sources` array is ordered by priority. In the next example, we'll add a source that can use a `?ref` query parameter to determine the referer. Additionally, we'll ignore `?utm_source` parameters. First, create the source implementations: ```php namespace App\Referer; use Illuminate\Http\Request; use Spatie\Referer\Source; class RefParameter implements Source { public function getReferer(Request $request): string { return $request->get('ref', ''); } } ``` Then register your source in the `sources` array. We'll also disable the `utm_source` while we're at it. ```php return [ // ... 'sources' => [ App\Referer\RefParameter::class, Spatie\Referer\Sources\RequestHeader::class, ], ]; ``` That's it! Source implementations can be this simple, or more advanced if necessary. ## Changelog Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. ## Testing ``` bash composer test ``` ## Contributing Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details. ## Security If you've found a bug regarding security please mail [[email protected]](mailto:[email protected]) instead of using the issue tracker. ## Credits - [Sebastian De Deyne](https://github.com/sebastiandedeyne) - [All Contributors](../../contributors) ## License The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

JavaScript Libraries & Components
526 Github Stars
laravel-missing-page-redirector
Open Source

laravel-missing-page-redirector

# Redirect missing pages in your Laravel application [![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-missing-page-redirector.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-missing-page-redirector) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) [![run-tests](https://github.com/spatie/laravel-missing-page-redirector/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-missing-page-redirector/actions/workflows/run-tests.yml) [![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-missing-page-redirector.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-missing-page-redirector) When transitioning from a old site to a new one your URLs may change. If your old site was popular you probably want to retain your SEO worth. One way of doing this is by providing [permanent redirects from your old URLs to your new URLs](https://support.google.com/webmasters/answer/93633?hl=en). This package makes that process very easy. When installed you only need to [add your redirects to the config file](https://github.com/spatie/laravel-missing-page-redirector#usage). Want to use the database as your source of redirects? [No problem](https://github.com/spatie/laravel-missing-page-redirector#creating-your-own-redirector)! ## Support us [<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-missing-page-redirector.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-missing-page-redirector) We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). ## Installation You can install the package via composer: ``` bash composer require spatie/laravel-missing-page-redirector ``` The package will automatically register itself. Next, prepend/append the `Spatie\MissingPageRedirector\RedirectsMissingPages` middleware to your global middleware stack: ```php // bootstrap/app.php ->withMiddleware(function (Middleware $middleware) { $middleware->append([ \Spatie\MissingPageRedirector\RedirectsMissingPages::class, ]); }) ``` Finally you must publish the config file: ```php php artisan vendor:publish --provider="Spatie\MissingPageRedirector\MissingPageRedirectorServiceProvider" ``` This is the contents of the published config file: ```php return [ /* * This is the class responsible for providing the URLs which must be redirected. * The only requirement for the redirector is that it needs to implement the * `Spatie\MissingPageRedirector\Redirector\Redirector`-interface */ 'redirector' => \Spatie\MissingPageRedirector\Redirector\ConfigurationRedirector::class, /* * By default the package will only redirect 404s. If you want to redirect on other * response codes, just add them to the array. Leave the array empty to redirect * always no matter what the response code. */ 'redirect_status_codes' => [ \Symfony\Component\HttpFoundation\Response::HTTP_NOT_FOUND ], /* * When using the `ConfigurationRedirector` you can specify the redirects in this array. * You can use Laravel's route parameters here. */ 'redirects' => [ // '/non-existing-page' => '/existing-page', // '/old-blog/{url}' => '/new-blog/{url}', ], ]; ``` ## Usage Creating a redirect is easy. You just have to add an entry to the `redirects` key in the config file. ```php 'redirects' => [ '/non-existing-page' => '/existing-page', ], ``` You may use route parameters like you're used to when using Laravel's routes: ```php 'redirects' => [ '/old-blog/{url}' => '/new-blog/{url}', ], ``` Optional parameters are also... an option: ```php 'redirects' => [ '/old-blog/{url?}' => '/new-blog/{url}', ], ``` Finally, you can use an asterix (`*`) as a wildcard parameter that will match multiple URL segments (see [encoded URL slashes in the Laravel docs](https://laravel.com/docs/master/routing#parameters-encoded-forward-slashes) for more info). This is useful when you want to redirect a URL like `/old-blog/foo/bar/baz` to `/new-blog/foo/bar/baz`. ```php 'redirects' => [ '/old-blog/*' => '/new-blog/{wildcard}', // {wilcard} will be the entire path ], ``` By default the package only redirects if the request has a `404` response code but it's possible to be redirected on any response code. To achieve this you may change the ```redirect_status_codes``` option to an array of response codes or leave it empty if you wish to be redirected no matter what the response code was sent to the URL. You may override this using the following syntax to achieve this: ```php 'redirect_status_codes' => [\Symfony\Component\HttpFoundation\Response::HTTP_NOT_FOUND], ``` It is also possible to optionally specify which http response code is used when performing the redirect. By default the ```301 Moved Permanently``` response code is set. You may override this using the following syntax: ```php 'redirects' => [ 'old-page' => ['/new-page', 302], ], ``` ## Events The package will fire a `RouteWasHit` event when it found a redirect for the route. A `RedirectNotFound` is fired when no redirect was found. ## Creating your own redirector By default this package will use the `Spatie\MissingPageRedirector\Redirector\ConfigurationRedirector` which will get its redirects from the config file. If you want to use another source for your redirects (for example a database) you can create your own redirector. A valid redirector is any class that implements the `Spatie\MissingPageRedirector\Redirector\Redirector`-interface. That interface looks like this: ```php namespace Spatie\MissingPageRedirector\Redirector; use Symfony\Component\HttpFoundation\Request; interface Redirector { public function getRedirectsFor(Request $request): array; } ``` The `getRedirectsFor` method should return an array in which the keys are the old URLs and the values the new URLs. ## If you want to use `Route::fallback` If you do not wish to overwrite the default redirector, or if you already have existing `Route::fallback` logic based on [laravel docs](https://laravel.com/docs/11.x/routing#fallback-routes), you can use this package as follow. In the bottom of your `web.php` file, ```php use Spatie\MissingPageRedirector\MissingPageRouter; //... Your other route Route::fallback(function (Request $request) { $redirectResponse = app(MissingPageRouter::class)->getRedirectFor($request); if ($redirectResponse !== null) { return $redirectResponse; } //... Your other logic }); ``` You can adjust the priority of redirect base on your needs. ## Changelog Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. ## Testing ``` bash $ composer test ``` ## Contributing Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details. ## Security If you've found a bug regarding security please mail [[email protected]](mailto:[email protected]) instead of using the issue tracker. ## Credits - [Freek Van der Herten](https://github.com/freekmurze) - [All Contributors](../../contributors) ## License The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

JavaScript Libraries & Components
510 Github Stars
laravel-robots-middleware
Open Source

laravel-robots-middleware

# Enable or disable the indexing of your app [![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-robots-middleware.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-robots-middleware) [![run-tests](https://github.com/spatie/laravel-robots-middleware/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-robots-middleware/actions/workflows/run-tests.yml) ![Check & fix styling](https://github.com/spatie/laravel-robots-middleware/workflows/Check%20&%20fix%20styling/badge.svg) [![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-robots-middleware.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-robots-middleware) A tiny, opinionated package to enable or disable indexing your site via a middleware in Laravel. More on the Robots meta tag: https://developers.google.com/webmasters/control-crawl-index/docs/robots_meta_tag Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource). ## Support us [<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-robots-middleware.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-robots-middleware) We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). ## Installation You can install the package via composer: ``` bash $ composer require spatie/laravel-robots-middleware ``` ## Usage By default, the middleware enables indexing on all pages. You'll probably want to inherit your own class containing you application's indexing rule handler. ```php // app/Http/Middleware/MyRobotsMiddleware.php namespace App\Http\Middleware; use Illuminate\Http\Request; use Spatie\RobotsMiddleware\RobotsMiddleware; class MyRobotsMiddleware extends RobotsMiddleware { /** * @return string|bool */ protected function shouldIndex(Request $request) { return $request->segment(1) !== 'admin'; } } ``` Next, simply register the newly created class in your middleware stack. ```php // app/Http/Kernel.php class Kernel extends HttpKernel { protected $middleware = [ // ... \App\Http\Middleware\MyRobotsMiddleware::class, ]; // ... } ``` That's it! Responses will now always have an `x-robots-tag` in their headers, containing an `all` or `none` value. ## Changelog Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. ## Testing ``` bash $ composer test ``` ## Contributing Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details. Due to nature of this package, there's a fair chance features won't be accepted to keep it light and opinionated. ## Security If you've found a bug regarding security please mail [[email protected]](mailto:[email protected]) instead of using the issue tracker. ## Credits - [Sebastian De Deyne](https://github.com/sebastiandedeyne) - [All Contributors](../../contributors) ## License The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

CMS Plugins & Extensions SEO Tools
332 Github Stars
lighthouse-php
Open Source

lighthouse-php

<div align="left"> <a href="https://spatie.be/open-source?utm_source=github&utm_medium=banner&utm_campaign=lighthouse-php"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://spatie.be/packages/header/lighthouse-php/html/dark.webp"> <img alt="Logo for lighthouse-php" src="https://spatie.be/packages/header/lighthouse-php/html/light.webp"> </picture> </a> <h1>Run Google Lighthouse using PHP</h1> [![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/lighthouse-php.svg?style=flat-square)](https://packagist.org/packages/spatie/lighthouse-php) [![Tests](https://github.com/spatie/lighthouse-php/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/spatie/lighthouse-php/actions/workflows/run-tests.yml) [![Total Downloads](https://img.shields.io/packagist/dt/spatie/lighthouse-php.svg?style=flat-square)](https://packagist.org/packages/spatie/lighthouse-php) </div> [Google Lighthouse](https://developer.chrome.com/docs/lighthouse/overview/) is an open-source, automated tool for improving the quality of web pages. It has audits for performance, accessibility, progressive web apps, SEO and more. This package makes it easy to run Lighthouse using PHP. Here's an example on how to get the scores of the five categories of audits that Lighthouse offers. ```php use Spatie\Lighthouse\Lighthouse; // returns an instance of Spatie\Lighthouse\LighthouseResult $result = Lighthouse::url('https://example.com')->run(); $result->scores(); // returns an array like this one: /* * [ * 'performance' => 98, * 'accessibility' => 83, * 'best-practices' => 90, * 'seo' => 92, * 'pwa' => 43, * ] */ ``` It's easy to configure various options: ```php use Spatie\Lighthouse\Lighthouse; use Spatie\Lighthouse\Enums\Category; Lighthouse::url('https://example.com') ->userAgent('My user agent') ->headers(['MyExtraHeader' => 'HeaderValue']) ->categories(Category::Performance, Category::Accessibility) ->throttleCpu() ->maxWaitForLoad(5000) // Wait max 5 seconds for page load ->run(); ``` Here's how you can get the results of an audit: ```php $result->audit('first-contentful-paint') // returns this array /* * [ * 'id' => 'first-contentful-paint' * 'title' => 'First Contentful Paint' * 'score' => 0.98 * 'scoreDisplayMode' => 'numeric' * 'numericValue' => 1262.95 * 'numericUnit' => 'millisecond' * 'displayValue' => '1.3 s' * ] */ ``` You can also write a full HTML report to disk: ```php $result->saveHtml($pathToReport) ``` ## Support us [<img src="https://github-ads.s3.eu-central-1.amazonaws.com/lighthouse-php.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/lighthouse-php) We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). ## Documentation All documentation is available [on our documentation site](https://spatie.be/docs/lighthouse-php). ## Testing ```bash composer test ``` ## Changelog Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. ## Contributing Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details. ## Security Vulnerabilities Please review [our security policy](../../security/policy) on how to report security vulnerabilities. ## Credits - [Freek Van der Herten](https://github.com/freekmurze) - [All Contributors](../../contributors) This package contains code copied from [Laravel's `Arr` class](https://github.com/laravel/framework/blob/9.x/src/Illuminate/Collections/Arr.php). ## License The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

SEO Tools Design Systems & Tokens Testing & QA
269 Github Stars
laravel-og-image
Open Source

laravel-og-image

<div align="left"> <a href="https://spatie.be/open-source?utm_source=github&utm_medium=banner&utm_campaign=laravel-og-image"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://spatie.be/packages/header/laravel-og-image/html/dark.webp?123"> <img alt="Logo for Laravel Open Graph Image" src="https://spatie.be/packages/header/laravel-og-image/html/light.webp?123"> </picture> </a> <h1>Generate OG images for your Laravel app</h1> [![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-og-image.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-og-image) [![GitHub Tests Action Status](https://github.com/spatie/laravel-og-image/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-og-image/actions?query=workflow%3Arun-tests+branch%3Amain) [![GitHub Code Style Action Status](https://github.com/spatie/laravel-og-image/actions/workflows/fix-php-code-style-issues.yml/badge.svg)](https://github.com/spatie/laravel-og-image/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain) [![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-og-image.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-og-image) </div> This package makes it easy to generate Open Graph images for your Laravel application. Define your OG image HTML inline in your Blade views, and the package automatically generates screenshot images using [spatie/laravel-screenshot](https://github.com/spatie/laravel-screenshot), serves them via a dedicated route, and caches them on disk. Your OG image templates inherit your page's existing CSS, fonts, and Vite assets. No separate CSS configuration needed. No external API needed. Everything runs on your own server. ## Support us [<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-og-image.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-og-image) We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). ## Documentation You'll find full documentation on [our documentation site](https://spatie.be/docs/laravel-og-image). ## Basic usage Use the Blade component to define your OG image inline: ```blade <x-og-image> <div class="w-full h-full bg-blue-900 text-white flex items-center justify-center"> <h1 class="text-6xl font-bold">{{ $post->title }}</h1> </div> </x-og-image> ``` This outputs a hidden `<template>` tag and `<meta>` tags pointing to a generated screenshot of your HTML at 1200×630 pixels. ## How it works 1. Your HTML is rendered inside a `<template data-og-image>` tag on the page 2. The page URL is cached, keyed by the md5 hash of the HTML content 3. Meta tags point to `/og-image/{hash}.jpeg` 4. When that URL is first requested, the page is visited with `?ogimage` appended, rendering just the template content with the page's full CSS at 1200×630 5. The generated image is saved to your public disk and served directly with cache headers 6. Subsequent requests serve the image from disk (or CDN cache) Preview any OG image by appending `?ogimage` to the page URL. ## Installation You can install the package via composer: ```bash composer require spatie/laravel-og-image ``` This package requires [spatie/laravel-screenshot](https://github.com/spatie/laravel-screenshot), which uses Browsershot under the hood. Make sure you have Node.js and a Chrome/Chromium binary installed. You can optionally publish the config file: ```bash php artisan vendor:publish --tag="og-image-config" ``` ## Testing ```bash composer test ``` ## Changelog Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. ## Contributing Please see [CONTRIBUTING](CONTRIBUTING.md) for details. ## Security Vulnerabilities Please review [our security policy](../../security/policy) on how to report security vulnerabilities. ## Credits - [Freek Van der Herten](https://github.com/freekmurze) - [All Contributors](../../contributors) ## License The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

WordPress Themes & Plugins SEO Tools
34 Github Stars
laravel-newsletter
Open Source

laravel-newsletter

<div align="left"> <a href="https://spatie.be/open-source?utm_source=github&utm_medium=banner&utm_campaign=laravel-newsletter"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://spatie.be/packages/header/laravel-newsletter/html/dark.webp"> <img alt="Logo for laravel-newsletter" src="https://spatie.be/packages/header/laravel-newsletter/html/light.webp"> </picture> </a> <h1>Manage newsletters in Laravel</h1> [![Latest Version](https://img.shields.io/github/release/spatie/laravel-newsletter.svg?style=flat-square)](https://github.com/spatie/laravel-newsletter/releases) [![MIT Licensed](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) [![run-tests](https://github.com/spatie/laravel-newsletter/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-newsletter/actions/workflows/run-tests.yml) [![PHPStan](https://github.com/spatie/laravel-newsletter/actions/workflows/phpstan.yml/badge.svg)](https://github.com/spatie/laravel-newsletter/actions/workflows/phpstan.yml) [![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-newsletter.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-newsletter) </div> This package provides an easy way to integrate subscriptions to email lists of various email services. Currently this package support: - [Mailcoach](https://mailcoach.app) (built by us :-)) - [MailChimp](https://mailchimp.com) - [MailerLite](https://mailerlite.com) ## Support us [<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-newsletter.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-newsletter) We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). ## Installation You can install this package via Composer using: ```bash composer require spatie/laravel-newsletter ``` To publish the config file to `config/newsletter.php` run: ```bash php artisan vendor:publish --tag="newsletter-config" ``` This will publish a file `newsletter.php` in your config directory with the following contents: ```php return [ /* * The driver to use to interact with MailChimp API. * You may use "log" or "null" to prevent calling the * API directly from your environment. */ 'driver' => env('NEWSLETTER_DRIVER', Spatie\Newsletter\Drivers\MailcoachDriver::class), /** * These arguments will be given to the driver. */ 'driver_arguments' => [ 'api_key' => env('NEWSLETTER_API_KEY'), 'endpoint' => env('NEWSLETTER_ENDPOINT'), ], /* * The list name to use when no list name is specified in a method. */ 'default_list_name' => 'subscribers', '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' => [ /* * When using the Mailcoach driver, this should be the Email list UUID * which is displayed in the Mailcoach UI * * When using the MailChimp driver, this should be a MailChimp list id. * http://kb.mailchimp.com/lists/managing-subscribers/find-your-list-id. * * When using the MailerLite driver, this should be a MailerLite group id. */ 'id' => env('NEWSLETTER_LIST_ID'), ], ], ]; ``` ### Using Mailcoach To let this package work with Mailcoach, you need to install the Mailcoach SDK. ```bash composer require spatie/mailcoach-sdk-php ``` Next, you must provide values for the API key, endpoint and `list.subscribers.id` in the config file. You'll find the API key and endpoint in the [Mailcoach](https://mailcoach.app) settings screen. The value for `list.subscribers.id` must be the UUID of an email list on Mailcoach. You'll find this value on the settings screen of an email list ### Using MailChimp To use MailChimp, install this extra package. ```bash composer require drewm/mailchimp-api ``` The `driver` key of the `newsletter` config file must be set to `Spatie\Newsletter\Drivers\MailChimpDriver::class`. Next, you must provide values for the API key and `list.subscribers.id`. You'll find these values in the MailChimp UI. The `endpoint` config value must be set to null. ### Using MailerLite To use MailerLite, install this extra package. ```bash composer require mailerlite/mailerlite-php ``` The `driver` key of the `newsletter` config file must be set to `Spatie\Newsletter\Drivers\MailerLiteDriver::class`. You need to provide the API key and the `group.id`. These can be found in your MailerLite Dashboard under Integrations > API. The `endpoint` config value must be set to null. ## Usage After you've installed the package and filled in the values in the config-file working with this package will be a breeze. All the following examples use the facade. Don't forget to import it at the top of your file. ```php use Spatie\Newsletter\Facades\Newsletter; ``` ### Subscribing, updating and unsubscribing Subscribing an email address can be done like this: ```php use Newsletter; Newsletter::subscribe('[email protected]'); ``` Let's unsubscribe someone: ```php Newsletter::unsubscribe('[email protected]'); ``` For Mailcoach, you can pass extra attributes as the second argument: ```php Newsletter::subscribe('[email protected]', ['first_name' => 'Rince', 'last_name' => 'Wind']); ``` For MailChimp you can pass merge variables as the second argument: ```php Newsletter::subscribe('[email protected]', ['FNAME'=>'Rince', 'LNAME'=>'Wind']); ``` For MailerLite you can pass subscriber fields as the second argument: ```php Newsletter::subscribe('[email protected]', ['name'=>'Rince', 'last_name'=>'Wind']); ``` You can subscribe someone to a specific list by passing a list name: ```php Newsletter::subscribe('[email protected]', listName: 'subscribers'); ``` That third argument is the name of a list you configured in the config file. You can also subscribe and/or update someone. The person will be subscribed or updated if he/she is already subscribed: ```php Newsletter::subscribeOrUpdate('[email protected]', ['first_name' => 'Rince', 'last_name' => 'Wind']); ``` For MailChimp, You can subscribe someone to one or more specific group(s)/interest(s) by using the fourth argument: ```php Newsletter::subscribeOrUpdate( '[email protected]', ['FNAME'=>'Rince','LNAME'=>'Wind'], 'subscribers', ['interests'=>['interestId'=>true, 'interestId'=>true]], ); ``` Simply add `false` if you want to remove someone from a group/interest. Here's how to unsubscribe someone from a specific list: ```php Newsletter::unsubscribe('[email protected]', 'subscribers'); ``` For MailerLite, passing a list name as the second argument removes the subscriber from the matching group. Without a list name, the subscriber is marked as unsubscribed across the account. ### Deleting subscribers Deleting is not the same as unsubscribing. Unlike unsubscribing, deleting a member will result in the loss of all history (add/opt-in/edits) as well as removing them from the list. In most cases, you want to use `unsubscribe` instead of `delete`. Here's how to perform a delete: ```php Newsletter::delete('[email protected]'); ``` ### Getting subscriber info You can get information on a subscriber by using the `getMember` function: ```php Newsletter::getMember('[email protected]'); ``` For MailCoach, this will return an instance of `Spatie\Mailcoach\Resources|Subscriber` For MailChimp, this will return an array with information on the subscriber. If there's no one subscribed with that e-mail address the function will return `false` There's also a convenient method to check if someone is already subscribed: ```php Newsletter::hasMember('[email protected]'); //returns a boolean ``` In addition to this, you can also check if a user is subscribed to your list: ```php Newsletter::isSubscribed('[email protected]'); //returns a boolean ``` ### Need something else? If you need more functionality you get an instance of the underlying API with ```php $api = Newsletter::getApi(); ``` If you're having trouble getting the MailChimp integration, you can see the last error with: ```php Newsletter::getApi()->getLastError(); ``` ## Testing Run the tests with: ```bash vendor/bin/pest ``` ### Changelog Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. ## Contributing Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details. ## Security If you discover any security-related issues, please email [[email protected]](mailto:[email protected]) instead of using the issue tracker. ## Credits - [Freek Van der Herten](https://github.com/freekmurze) - [All Contributors](../../contributors) be dedicated to allocating workforce on maintenance and new awesome stuff. ## License The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

WordPress Themes & Plugins Email Marketing
1.6K Github Stars
Mailcoach
Open Source

Mailcoach

<img width="450" alt="Mailcoach" src="https://github.com/spatie/Mailcoach/assets/3626559/be10e73d-e1f5-42ea-870f-38c40176939e"> # Mailcoach Self-Hosted Powerful email marketing, automations and transactional emails, seamlessly integrated into your Laravel application. Mailcoach Self-Hosted lets you manage your contact lists and send marketing, automated and transactional emails from within Laravel. - Send marketing emails with all the features you need—including segmentation, split testing, and helpful analytics. - Automate your email marketing and create powerful workflows for onboarding or generating leads. - Edit, send and track transactional emails directly in Mailcoach Read our documentation on [how to get started](https://mailcoach.app/self-hosted). ## Support us [<img src="https://github-ads.s3.eu-central-1.amazonaws.com/mailcoach.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/Mailcoach) We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Storage & Backup Email Marketing
402 Github Stars