Ejemplo n.º 1
0
 public function store(Request $request)
 {
     $this->validate($request, ['course_id' => 'required|exists:courses,id', 'name' => 'required', 'description' => 'required', 'file' => 'max:10000|mimes:pdf'], ['required' => 'Kolom :attribute diperlukan']);
     $data = $request->except('file');
     if ($request->hasFile('file')) {
         $data['file'] = $this->upload($request->file('file'));
     }
     $course = Module::create($data);
     \Flash::success('Module berhasil ditambahkan.');
     return redirect()->back();
 }
Ejemplo n.º 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $validator = Validator::make($request->all(), ['name' => 'required|string', 'height' => 'integer', 'width' => 'required|integer', 'quantity' => 'required|integer', 'modulenature_id' => 'required|integer', 'project_id' => 'required|integer']);
     if ($validator->fails()) {
         return response()->json($validator->errors()->all(), 400);
     }
     try {
         $modulenature = Modulenature::findOrFail($request->input('modulenature_id'));
     } catch (Exception $e) {
         return response()->json('La nature de module n\'existe pas.', 404);
     }
     try {
         $project = Project::findOrFail($request->input('project_id'));
     } catch (Exception $e) {
         return response()->json('Le projet n\'existe pas.', 404);
     }
     $module = Module::create($request->all());
     return $module;
 }