app/Http/Controllers/ImageCourseController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $data = $request->all();
        $rules = [
            "image" => "required|url",
            "course_id" => 'required|integer'
        ];
        $validator = Validator::make($data, $rules);
        if ($validator->fails()) {
            return response()->json([
                'status' => "error",
                "message" => $validator->errors()
            ], 400);
        }
        $course = Course::find($request->input('course_id'));
        if (!$course) {
            return response()->json([
                "status" => "error",
                "message" => "course not found"
            ], 404);
        }
        $imageCourse = ImageCourse::create($data);
        return response()->json([
            "status" => "success",
            "data" => $imageCourse
        ]);
    }
public function store ( Request $ request ) { $ data = $ request -> all ( ) ; $ rules = [ " image " => " required|url " , " course_id " => 'required|integer' ] ; $ validator = Validator :: make ( $ data , $ rules ) ; if ( $ validator -> fails ( ) ) { return response ( ) -> json ( [ 'status' => " error " , " message " => $ validator -> errors ( ) ] , 400 ) ; } $ course = Course :: find ( $ request -> input ( 'course_id' ) ) ; if ( ! $ course ) { return response ( ) -> json ( [ " status " => " error " , " message " => " course not found " ] , 404 ) ; } $ imageCourse = ImageCourse :: create ( $ data ) ; return response ( ) -> json ( [ " status " => " success " , " data " => $ imageCourse ] ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .