Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tag update #6

Merged
merged 16 commits into from
May 30, 2018
Prev Previous commit
Next Next commit
done
  • Loading branch information
ro4 committed May 29, 2018
commit da098c9da86a6d34faa1fede5ca355c4c7bbda68
22 changes: 19 additions & 3 deletions app/Http/Controllers/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,26 @@ class TagController extends Controller

public function store(Request $request)
{
$page_id = $request->input('p');
$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($request->input('p'));
$names = explode(',', $request->input('tags'));
$tags = [];
$page = Document::findOrFail($page_id);
$names = explode(',', $tags);
$tags = [];
foreach ($names as $name) {
$tags[] = Tag::firstOrCreate(['name' => $name])->toArray();
}
Expand Down