本文整理汇总了PHP中app\Course::categories方法的典型用法代码示例。如果您正苦于以下问题:PHP Course::categories方法的具体用法?PHP Course::categories怎么用?PHP Course::categories使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Course
的用法示例。
在下文中一共展示了Course::categories方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
}