Skip to content

Commit

Permalink
Merge pull request #97 from 0plus1/laravel-5
Browse files Browse the repository at this point in the history
Added Lumen support and removed unnecessary usage of Facades
  • Loading branch information
rtconner committed Apr 7, 2016
2 parents f4995f4 + 295c518 commit 1380d50
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 7 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ This package is not meant to handle javascript or html in any way. This package

There are no real limits on what characters can be used in a tag. It uses a slug transform to determine if two tags are identical ("sugar-free" and "Sugar Free" would be treated as the same tag). Tag display names are run through Str::title()

[Laravel 5 Documentation](https://github.com/rtconner/laravel-tagging/tree/laravel-5)
[Laravel/Lumen 5 Documentation](https://github.com/rtconner/laravel-tagging/tree/laravel-5)
[Laravel 4 Documentation](https://github.com/rtconner/laravel-tagging/tree/laravel-4)

#### Composer Install (for Laravel 5)
#### Composer Install (for Laravel/Lumen 5)

```shell
composer require rtconner/laravel-tagging "~2.0"
Expand All @@ -33,6 +33,22 @@ php artisan vendor:publish --provider="Conner\Tagging\Providers\TaggingServicePr
php artisan migrate
```

###### lumen

Laravel does not have a vendor:publish command, so you will need to create or copy the provided migrations and config file into their respective directory.

In app\bootstrap\app.php

```php
// Add this line in your config section
$app->configure('tagging');
// Add this line in your service provider section
$app->register(Conner\Tagging\Providers\LumenTaggingServiceProvider::class);
```

Done. Eloquent is required, Facades are not.


After these two steps are done, you can edit config/tagging.php with your prefered settings.

#### Setup your models
Expand Down
2 changes: 1 addition & 1 deletion migrations/2014_01_07_073615_create_tagged_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CreateTaggedTable extends Migration {
public function up() {
Schema::create('tagging_tagged', function(Blueprint $table) {
$table->increments('id');
if(\Config::get('tagging.primary_keys_type') == 'string') {
if(config('tagging.primary_keys_type') == 'string') {
$table->string('taggable_id', 36)->index();
} else {
$table->integer('taggable_id')->unsigned()->index();
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(array $attributes = array())
*/
public function save(array $options = array())
{
$validator = \Validator::make(
$validator = app('validator')->make(
array('name' => $this->name),
array('name' => 'required|min:1')
);
Expand Down
41 changes: 41 additions & 0 deletions src/Providers/LumenTaggingServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Conner\Tagging\Providers;

use Illuminate\Support\ServiceProvider;
use Conner\Tagging\Contracts\TaggingUtility;
use Conner\Tagging\Util;

/**
* Copyright (C) 2014 Robert Conner
*/
class LumenTaggingServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application events.
*/
public function boot()
{
}

/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->singleton(TaggingUtility::class, function () {
return new Util;
});
}

/**
* (non-PHPdoc)
* @see \Illuminate\Support\ServiceProvider::provides()
*/
public function provides()
{
return [TaggingUtility::class];
}
}
5 changes: 2 additions & 3 deletions src/Taggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Conner\Tagging\Events\TagRemoved;
use Conner\Tagging\Model\Tagged;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Config;

/**
* Copyright (C) 2014 Robert Conner
Expand Down Expand Up @@ -301,15 +300,15 @@ public static function untagOnDelete()
{
return isset(static::$untagOnDelete)
? static::$untagOnDelete
: Config::get('tagging.untag_on_delete');
: config('tagging.untag_on_delete');
}

/**
* Delete tags that are not used anymore
*/
public static function shouldDeleteUnused()
{
return Config::get('tagging.delete_unused_tags');
return config('tagging.delete_unused_tags');
}

/**
Expand Down

0 comments on commit 1380d50

Please sign in to comment.