Exemplo n.º 1
0
 /**
  * @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');
 }