本文整理汇总了PHP中app\Course::update方法的典型用法代码示例。如果您正苦于以下问题:PHP Course::update方法的具体用法?PHP Course::update怎么用?PHP Course::update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Course
的用法示例。
在下文中一共展示了Course::update方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: course
/**
* Created By Dara on 8/2/2016
* add reply to comment
*/
public function course(Course $course, $comment_id, Request $request)
{
$user = $this->user;
$this->validate($request, ['content' => 'required']);
if ($comment_id) {
//check if the comment has been set or not (reply) level 2 comment
$comment = Comment::findOrFail($comment_id);
$parent_id = $comment->id;
$msg = trans('users.answerSent');
$nested = true;
} else {
//level 1 comment
$parent_id = 0;
$msg = trans('users.commentSent');
$nested = false;
}
//add comment to db
$newComment = $course->comments()->create(['user_id' => $user->id, 'content' => $request->input('content'), 'parent_id' => $parent_id]);
$numComment = $course->comments()->count();
$course->update(['num_comment' => $numComment]);
$obj = $course;
$model = 'course';
return ['hasCallback' => 1, 'callback' => 'course_comment', 'hasMsg' => 1, 'msgType' => '', 'msg' => $msg, 'returns' => ['newComment' => view('comment.comment', compact('newComment', 'course', 'user', 'obj', 'model'))->render(), 'nested' => $nested, 'numComment' => $numComment]];
}
示例2: update
/**
* @param CourseRequest|CourseRequest $request
* @param Course $course
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
* @internal param $id
*/
public function update(CourseRequest $request, Course $course)
{
$course->update($request->all());
$this->syncTags($course, $request->input('tag_list'));
return redirect('main');
}
示例3: update
public function update(Course $course, Request $request)
{
$user = $this->user;
$this->validate($request, ['title' => 'required|min:3', 'active' => 'required|in:0,1', 'description' => 'required|min:3', 'categories.*' => 'integer', 'price' => 'required|integer', 'image' => 'mimes:jpeg,bmp,png,jpg|max:1024']);
$input = $request->all();
$previousImage = $course->image;
/* check if the user has uploaded image or not */
if ($request->hasFile('image')) {
$image = $input['image'];
$imageName = $user->id . str_random(20) . '.' . $image->getClientOriginalExtension();
$dbImageName = $user->id . '/' . $imageName;
$image->move(public_path() . '/img/files/' . $user->id, $imageName);
if ($previousImage != null) {
if (File::exists(public_path() . '/img/files/' . $previousImage)) {
unlink(public_path() . '/img/files/' . $previousImage);
}
}
} else {
$dbImageName = $previousImage;
}
/*create course*/
$course->update(['title' => $input['title'], 'description' => $input['description'], 'active' => $input['active'], 'price' => $input['price'], 'image' => $dbImageName]);
/*register subCategories*/
$selectedCategories = $this->registerSubCategories($request);
if (!$selectedCategories) {
//if the selected tags has error
return redirect()->back();
}
$course->categories()->sync($selectedCategories);
/*register tags*/
$selected = $this->registerTags($request);
if (!$selected) {
//if the selected tags has error
return redirect()->back();
}
$course->tags()->sync($selected);
Flash::success(trans('users.courseUpdated'));
return redirect()->back();
}