本文整理汇总了PHP中app\models\Course::fill方法的典型用法代码示例。如果您正苦于以下问题:PHP Course::fill方法的具体用法?PHP Course::fill怎么用?PHP Course::fill使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Course
的用法示例。
在下文中一共展示了Course::fill方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* @param Request $request
* @param Course $course
* @return \Illuminate\Http\RedirectResponse
*/
public function store(Request $request, Course $course)
{
$regex = '/^(?=.+)(?:[1-9]\\d*|0)?(?:\\.\\d+)?$/';
$validator = Validator::make($request->all(), ['name' => 'required|string|max:255', 'course_purchase' => ['required', 'regex:' . $regex]]);
if ($validator->fails()) {
return redirect()->route('admin.course.create')->withErrors($validator->errors())->withInput();
}
$currency = new Currency();
$currency->name = $request->name;
$currency->save();
$course->currency()->associate($currency);
$course->fill($request->all());
$course->save();
return redirect()->route('admin.course.index');
}
示例2: actionSave
public function actionSave()
{
if (!empty($_POST['course'][Course::PK])) {
$item = Course::findByPK($_POST['course'][Course::PK]);
} else {
$item = new Course();
}
$item->fill($_POST['course']);
$item->save();
if ($item->wasNew() && !empty($_POST['lessonsCount'])) {
$lessonsCount = (int) $_POST['lessonsCount'];
for ($i = 1; $i <= $lessonsCount; $i++) {
$lesson = new Lesson();
$lesson->num = $i;
$lesson->title = 'Урок ' . $i;
$lesson->course = $item;
$lesson->save();
}
}
$this->redirect('/admin/courses');
}