本文整理汇总了PHP中app\Task::tags方法的典型用法代码示例。如果您正苦于以下问题:PHP Task::tags方法的具体用法?PHP Task::tags怎么用?PHP Task::tags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Task
的用法示例。
在下文中一共展示了Task::tags方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
// validate input
$this->validate($request, ['name' => 'required|max:255|min:5', 'priority' => 'required']);
$task = new Task();
$task->owner_id = Auth::user()->id;
// TODO: Why doesn't $request->user() work?
$task->creator_id = Auth::user()->id;
$task->name = $request->get('name');
$task->priority = $request->get('priority');
// TODO: Fix/re-think these? Is checking $saved correct? what about try/catch
$task->description = $request->get('description');
$task->status = 'open';
// make constant?
if ($request->get('due_date')) {
$task->due_date = date('Y-m-d H:i:s', strtotime($request->get('due_date')));
}
$saved = $task->save();
if ($saved) {
$tagsForThisTask = [];
if ($request->get('tags')) {
foreach ($request->get('tags') as $tag) {
// TODO: change variable names?
$firstOrCreate = Tag::firstOrCreate(['tag' => $tag]);
$tagsForThisTask[] = $firstOrCreate->id;
}
}
$task->tags()->sync($tagsForThisTask);
// if this..
$assigneesForThisTask = [];
if ($request->get('assignees')) {
foreach ($request->get('assignees') as $user) {
$assigneesForThisTask[] = $user;
}
}
$task->assignees()->sync($assigneesForThisTask);
// if this..
}
// TODO: If saved...
// TODO: better way to flash messages?
return redirect()->action('TaskController@show', $task)->with('message-type', 'success')->with('message-message', 'New task created!');
// TODO: Assignees
// TODO: Shares
// TODO: Approvers
// TODO: Attachments
// TODO: Email notifications
}
示例2: syncTags
/**
* sync tags to Task
* @param Task $task Object
* @return void
*/
private function syncTags(Task $task, array $tags)
{
if (is_array($tags)) {
$task->tags()->sync($tags);
}
}