Preface
Introduction
A Platform 3 extension to manage tags across your application.
Have a read through the Installation Guide.
Features
- Can create, update and remove tags.
- Can register entity namespaces.
- Can associate a tag to a namespace.
Examples
The $tags
variable used below is a reference to the TagRepository.
$tags = app('platform.tags');
Retrieve all tags
$allTags = $tags->findAll();
Dynamically create a new tag
$tags->create([
'name' => 'Foo',
'slug' => 'foo',
]);
Setup
Installation
The best and easiest way to install the Tags extension is with Composer.
Preparation
Open your composer.json
file and add the following to the require
array:
"platform/tags": "2.0.*"
Add the following lines after the require
array on your composer.json
file:
"repositories": [
{
"type": "composer",
"url": "https://packages.cartalyst.com"
}
]
Note: Make sure that after the required changes your
composer.json
file is valid by runningcomposer validate
.
Install the dependencies
Run Composer to install or update the new requirement.
php composer install
or
php composer update
Now you are able to install the extension through Platform's admin.
Usage
In this section we'll show how you can manage your application's tags.
Repository
IoC Binding
The tag repository is bound to platform.tags
and can be resolved out of the IoC Container using that offset.
$tags = app('platform.tags');
Methods
The repository contains several methods that are used throughout the extension, most common methods are listed below.
For an exhaustive list of available methods, checkout the TagRepositoryInterface
- findAll();
Returns a collection of all tags.
- find($id);
Returns a tag object based on the given id.
- findBySlug($slug);
Returns a tag object based on the given slug.
- findByName($name);
Returns a tag object based on the given name.
- create(array $data);
Creates a new tag.
- update($id, array $data);
Updates an existing tag.
- delete($id);
Deletes a tag.
- set($entity, $tags)
Sets the given tags on the given entity.