Skip to content

Commit

Permalink
v4 (#305)
Browse files Browse the repository at this point in the history
* New major version: v4 (PHP8+) (#303)

* only allow php ^8.0

* only run tests on PHP 8

* update gitignore

* convert phpdoc types to actual union types where appropriate; add several return types

* use laravel-package-tools package

* implement spatie/laravel-package-tools

* add Collection to union return type for findOrCreate()

* Fix styling

* update requirements doc with PHP >=8

* update changelog

* update doc link

* nitpicks

* nitpicks

* wip

* wip

* wip

* Fix styling

* wip

* wip

* wip

Co-authored-by: Patrick <[email protected]>
Co-authored-by: freekmurze <[email protected]>
  • Loading branch information
3 people authored Mar 9, 2021
1 parent 1c3fbda commit bafa520
Show file tree
Hide file tree
Showing 27 changed files with 117 additions and 190 deletions.
19 changes: 0 additions & 19 deletions .github/workflows/deploy-docs.yml

This file was deleted.

12 changes: 2 additions & 10 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ name: run-tests
on:
push:
pull_request:
schedule:
- cron: '0 0 * * *'

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
php: [8.0,7.4]
php: [8.0]
laravel: [8.*]
dependency-version: [prefer-lowest, prefer-stable]
os: [ubuntu-latest]
Expand All @@ -33,13 +31,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.idea
build
composer.lock
vendor
.env
.php_cs.cache
.phpunit.result.cache
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `laravel-tags` will be documented in this file

## 4.0.0 - 2021-03-09

- drop support for all PHP versions below 8.0

## 3.1.0 - 2021-03-01

-add `tag_model` config variable (#301)
Expand Down
4 changes: 4 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# From v3 to v4

There were no changes to the API, so you don't need to modify anything in your project code.

# From v2 to v3

There were no changes to the API, so you don't need to modify anything in your project code.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
}
],
"require": {
"php": "^7.4|^8.0",
"php": "^8.0",
"laravel/framework": "^8.0",
"spatie/eloquent-sortable": "^3.5",
"spatie/laravel-package-tools": "^1.4",
"spatie/laravel-translatable": "^4.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"orchestra/testbench": "^6.0",
"phpunit/phpunit": "^9.3"
"phpunit/phpunit": "^9.5"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion config/tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/*
* The given function generates a URL friendly "slug" from the tag name property before saving it.
* Defaults to Str::slug (https://laravel.com/docs/5.8/helpers#method-str-slug)
* Defaults to Str::slug (https://laravel.com/docs/master/helpers#method-str-slug)
*/
'slugger' => null,

Expand Down
9 changes: 3 additions & 6 deletions database/migrations/create_tag_tables.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,21 @@ class CreateTagTables extends Migration
{
Schema::create('tags', function (Blueprint $table) {
$table->id();

$table->json('name');
$table->json('slug');
$table->string('type')->nullable();
$table->integer('order_column')->nullable();

$table->timestamps();
});

Schema::create('taggables', function (Blueprint $table) {
$table->foreignId('tag_id')->constrained()->cascadeOnDelete();

$table->morphs('taggable');

$table->unique(['tag_id', 'taggable_id', 'taggable_type']);
});
}

public function down()
{
Schema::drop('taggables');
Schema::drop('tags');
}
}
2 changes: 1 addition & 1 deletion docs/_index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: v3
title: v4
slogan: A powerful tagging package. Batteries included.
githubUrl: https://github.com/spatie/laravel-tags
branch: master
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced-usage/adding-translations.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ $tag->name // returns the name of the tag in current locale of your app.
The translations of the tags are stored in the `name` column of the `tags` table. It's a `json` column. To find a tag with a specific translation you can just use Laravel's query builder which has support for `json` columns.

```php
\Spatie\Tags\Tag
\Spatie\Tags\Tag::query()
->where('name->fr', 'mon tag')
->first();
```
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced-usage/using-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ In addition to strings, all methods mentioned in the basic usage section can tak
```php
$newsItem->attachTag($tagWithType);
$newsItem->detachTag($tagWithType);
...
// ...
```

In addition to `syncTags`, an additional method called `syncTagsWithType` is available for syncing tags on a per-type basis:
Expand Down
5 changes: 3 additions & 2 deletions docs/advanced-usage/using-your-own-tag-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ You might want to override some functionality of the `Spatie\Tags\Tag` or add so

```php
use Illuminate\Database\Eloquent\Model;
use Spatie\Tags\HasTags;

class YourModel extends Model
{
use \Spatie\Tags\HasTags;
use HasTags;

public static function getTagClassName(): string
{
Expand All @@ -21,7 +22,7 @@ class YourModel extends Model

Then you need to override the `tags()` method from the same trait to tell Laravel that it still needs to look for `tags_id` column for tags relation instead of `your_tag_model_id`:

```
```php
use Illuminate\Database\Eloquent\Relations\MorphToMany;

public function tags(): MorphToMany
Expand Down
9 changes: 6 additions & 3 deletions docs/basic-usage/using-tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ weight: 1
To make an Eloquent model taggable just add the `\Spatie\Tags\HasTags` trait to it:

```php
class YourModel extends \Illuminate\Database\Eloquent\Model
use Illuminate\Database\Eloquent\Model;
use Spatie\Tags\HasTags;

class YourModel extends Model
{
use \Spatie\Tags\HasTags;
use HasTags;

...
}
Expand Down Expand Up @@ -95,4 +98,4 @@ You can fetch a collection of all registered tag types by using the static metho

```php
Tag::getTypes();
```
```
3 changes: 0 additions & 3 deletions docs/installation-and-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ You can install the package via composer:
composer require spatie/laravel-tags
```

The service provider will automatically be registered.

You can publish the migration with:
```bash
php artisan vendor:publish --provider="Spatie\Tags\TagsServiceProvider" --tag="migrations"
Expand All @@ -30,7 +28,6 @@ php artisan vendor:publish --provider="Spatie\Tags\TagsServiceProvider" --tag="c
This is the contents of the published config file:

```php
<?php
return [
/*
* The given function generates a URL friendly "slug" from the tag name property before saving it.
Expand Down
4 changes: 1 addition & 3 deletions docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ weight: 1

This package offers taggable behaviour for your models. After the package is installed the only thing you have to do is to add the `HasTags` trait to an Eloquent model to make it taggable.

But we didn't stop with the regular tagging capabilities you find in every package. Laravel Tags comes with batteries included. Out of the box it has support for [translating tags](/laravel-tags/v2/advanced-usage/adding-translations), [multiple tag types](/laravel-tags/v2/advanced-usage/using-types) and [sorting capabilities](/laravel-tags/v2/advanced-usage/sorting-tags).
We didn't stop with the regular tagging capabilities you find in every package. Laravel Tags comes with batteries included. Out of the box it has support for [translating tags](/laravel-tags/v2/advanced-usage/adding-translations), [multiple tag types](/laravel-tags/v2/advanced-usage/using-types) and [sorting capabilities](/laravel-tags/v2/advanced-usage/sorting-tags).

Here are some code examples:

Expand Down Expand Up @@ -64,7 +64,5 @@ Tag::containing('test'); // returns all tags that contain 'test'
<section class="article_badges">
<a href="https://packagist.org/packages/spatie/laravel-tags"><img src="https://img.shields.io/packagist/v/spatie/laravel-tags.svg?style=flat-square" alt="Latest Version on Packagist"></a>
<a href="https://github.com/spatie/laravel-tags/blob/master/LICENSE.md"><img src="https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square" alt="Software License"></a>
<a href="https://travis-ci.org/spatie/laravel-tags"><img src="https://img.shields.io/travis/spatie/laravel-tags/master.svg?style=flat-square" alt="Build Status"></a>
<a href="https://scrutinizer-ci.com/g/spatie/laravel-tags"><img src="https://img.shields.io/scrutinizer/g/spatie/laravel-tags.svg?style=flat-square" alt="Quality Score"></a>
<a href="https://packagist.org/packages/spatie/laravel-tags"><img src="https://img.shields.io/packagist/dt/spatie/laravel-tags.svg?style=flat-square" alt="Total Downloads"></a>
</section>
4 changes: 2 additions & 2 deletions docs/postcardware.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ weight: 2

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, Samberstraat 69D, 2060 Antwerp, Belgium.
Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

The best postcards will get published on the [open source section](https://spatie.be/en/opensource/postcards) on our website.
All postcards will get published on the [open source section](https://spatie.be/open-source/postcards) on our website.
2 changes: 1 addition & 1 deletion docs/requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ title: Requirements
weight: 3
---

This package requires Laravel 8 or higher, PHP 7.4 or higher and a database that supports `json` fields such as MySQL 5.7.8 or higher.
This package requires Laravel 8 or higher, PHP 8 or higher and a database that supports `json` fields such as MySQL 5.7.8 or higher.
8 changes: 6 additions & 2 deletions src/HasSlug.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ public static function bootHasSlug()
{
static::saving(function (Model $model) {
collect($model->getTranslatedLocales('name'))
->each(fn (string $locale) => $model->setTranslation('slug', $locale, $model->generateSlug($locale)));
->each(fn (string $locale) => $model->setTranslation(
'slug',
$locale,
$model->generateSlug($locale)
));
});
}

protected function generateSlug(string $locale): string
{
$slugger = config('tags.slugger');

$slugger = $slugger ?: '\Illuminate\Support\Str::slug';
$slugger ??= '\Illuminate\Support\Str::slug';

return call_user_func($slugger, $this->getTranslation('name', $locale));
}
Expand Down
Loading

0 comments on commit bafa520

Please sign in to comment.