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
add tags ajax api
  • Loading branch information
ro4 committed May 24, 2018
commit a658fe75ae1c8278157ee910ec3cd9a8d9fc6322
14 changes: 9 additions & 5 deletions app/Http/Controllers/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ class TagController extends Controller

public function store(Request $request)
{
/** @var Document $page */
$page = Document::findOrFail($request->input('p'));

$names = $request->input('tags');

$tags = Tag::whereIn('name', $names)->get();

dd($tags);
$tags = [];
foreach ($names as $name) {
$tags[] = Tag::firstOrCreate(['name' => $name])->toArray();
}
$page->tags()->detach();
$page->tags()->attach(array_pluck($tags, 'id'));

return $tags;
}

}
3 changes: 2 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@


Route::group(['prefix' => 'tag', 'as' => 'tag:'], function () {

// 创建标签
Route::post('/', 'TagController@store')->name('tag:store');
});
});
});