-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from ro4/master
tag update
- Loading branch information
Showing
13 changed files
with
889 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
|
||
use App\Repositories\Document; | ||
use App\Repositories\Tag; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Gate; | ||
|
||
class TagController extends Controller | ||
{ | ||
|
||
/** | ||
* store the tags | ||
* | ||
* @param Request $request | ||
* | ||
* @return array|string | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
$page_id = $request->input('p'); | ||
if (Gate::denies('project-edit', $page_id)) { | ||
return []; | ||
} | ||
$tags = $request->input('tags'); | ||
$this->validateParameters( | ||
[ | ||
'page_id' => $page_id, | ||
'tags' => $tags, | ||
], | ||
[ | ||
'page_id' => "required|integer", | ||
'tags' => 'nullable|max:500', | ||
], | ||
[ | ||
'tags.required' => '标签不能为空', | ||
'tags.between' => '标签最大不能超过500字符', | ||
] | ||
); | ||
/** @var Document $page */ | ||
$page = Document::findOrFail($page_id); | ||
$names = explode(',', $tags); | ||
$tags = []; | ||
foreach ($names as $name) { | ||
$tags[] = Tag::firstOrCreate(['name' => $name])->toArray(); | ||
} | ||
$page->tags()->detach(); | ||
$page->tags()->attach(array_pluck($tags, 'id')); | ||
|
||
return $tags; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Repositories; | ||
|
||
/** | ||
* Class Tag | ||
* | ||
* @property integer $id | ||
* @property integer $page_id | ||
* @property integer $tag_id | ||
* | ||
* @package App\Repositories | ||
*/ | ||
class PageTag extends Repository | ||
{ | ||
protected $table = 'wz_page_tag'; | ||
public $timestamps = false; | ||
protected $fillable = ['page_id', 'tag_id']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Repositories; | ||
|
||
use Carbon\Carbon; | ||
|
||
/** | ||
* Class Tag | ||
* | ||
* @property integer $id | ||
* @property string $name | ||
* @property Carbon $created_at | ||
* @property Carbon $updated_at | ||
* | ||
* @package App\Repositories | ||
*/ | ||
class Tag extends Repository | ||
{ | ||
protected $table = 'wz_tags'; | ||
protected $fillable = ['name']; | ||
|
||
/** | ||
* 标签的页面 | ||
* | ||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany | ||
*/ | ||
public function pages() | ||
{ | ||
return $this->belongsToMany(Document::class, 'wz_page_tag', 'tag_id', 'page_id'); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
database/migrations/2018_05_10_105015_create_tags_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CreateTagsTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('wz_tags', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('name', 255)->comment('用户ID')->unique(); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('wz_tags'); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
database/migrations/2018_05_10_105629_create_page_tag_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CreatePageTagTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('wz_page_tag', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->unsignedInteger('page_id')->comment('页面 ID'); | ||
$table->unsignedInteger('tag_id')->comment('标签 ID'); | ||
$table->index('page_id', 'idx_page_id'); | ||
$table->index('tag_id', 'idx_tag_id'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('wz_page_tag'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* DO NOT EDIT THIS FILE DIRECTLY | ||
* Compiled from bootstrap-tagmanager.less based on Bootstrap 2.3.1 variables | ||
* https://github.com/twitter/bootstrap/blob/master/less/variables.less | ||
*/ | ||
.tm-tag { | ||
color: #555555; | ||
background-color: #f5f5f5; | ||
border: #bbbbbb 1px solid; | ||
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset; | ||
display: inline-block; | ||
border-radius: 3px; | ||
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | ||
font-size: 13px; | ||
margin: 0 5px 5px 0; | ||
padding: 4px; | ||
text-decoration: none; | ||
transition: border 0.2s linear 0s, box-shadow 0.2s linear 0s; | ||
-moz-transition: border 0.2s linear 0s, box-shadow 0.2s linear 0s; | ||
-webkit-transition: border 0.2s linear 0s, box-shadow 0.2s linear 0s; | ||
vertical-align: middle; | ||
} | ||
.tm-tag .tm-tag-remove { | ||
color: #000000; | ||
font-weight: bold; | ||
margin-left: 4px; | ||
opacity: 0.2; | ||
} | ||
.tm-tag .tm-tag-remove:hover { | ||
color: #000000; | ||
text-decoration: none; | ||
opacity: 0.4; | ||
} | ||
.tm-tag.tm-tag-warning { | ||
color: #945203; | ||
background-color: #f2c889; | ||
border-color: #f0a12f; | ||
} | ||
.tm-tag.tm-tag-error { | ||
color: #84212e; | ||
background-color: #e69ca6; | ||
border-color: #d24a5d; | ||
} | ||
.tm-tag.tm-tag-success { | ||
color: #638421; | ||
background-color: #cde69c; | ||
border-color: #a5d24a; | ||
} | ||
.tm-tag.tm-tag-info { | ||
color: #4594b5; | ||
background-color: #c5eefa; | ||
border-color: #5dc8f7; | ||
} | ||
.tm-tag.tm-tag-inverse { | ||
color: #cccccc; | ||
background-color: #555555; | ||
border-color: #333333; | ||
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2) inset; | ||
} | ||
.tm-tag.tm-tag-inverse .tm-tag-remove { | ||
color: #ffffff; | ||
} | ||
.tm-tag.tm-tag-large { | ||
font-size: 16.25px; | ||
border-radius: 4px; | ||
padding: 11px 7px; | ||
} | ||
.tm-tag.tm-tag-small { | ||
font-size: 11.049999999999999px; | ||
border-radius: 3px; | ||
padding: 2px 4px; | ||
} | ||
.tm-tag.tm-tag-mini { | ||
font-size: 9.75px; | ||
border-radius: 2px; | ||
padding: 0px 2px; | ||
} | ||
.tm-tag.tm-tag-plain { | ||
color: #333333; | ||
box-shadow: none; | ||
background: none; | ||
border: none; | ||
} | ||
.tm-tag.tm-tag-disabled { | ||
color: #aaaaaa; | ||
background-color: #e6e6e6; | ||
border-color: #cccccc; | ||
box-shadow: none; | ||
} | ||
.tm-tag.tm-tag-disabled .tm-tag-remove { | ||
display: none; | ||
} | ||
input[type="text"].tm-input { | ||
margin-bottom: 5px; | ||
vertical-align: middle !important; | ||
} | ||
.control-group.tm-group { | ||
margin-bottom: 5px; | ||
} | ||
.form-horizontal .control-group.tm-group { | ||
margin-bottom: 15px; | ||
} |
Oops, something went wrong.