app/Http/Controllers/MaterialController.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)
    {
        $inputs = $request->all();
        $validation = (new Material)->validation($inputs);
        if($validation->fails()) {
            return jsonResponse(false, 206, $validation->getMessageBag());
        }
        try {
            \DB::beginTransaction();
            if($request->hasFile('image')) {
                $inputs['image'] = uploadImg($request, 'image', env('MATERIAL_PATH'));
            }
            $inputs['created_by'] = authId();
            (new Material)->store($inputs);
            \DB::commit();
            $extra = ['redirect' => route('material.index')];
            $message = __('message.created', ['attr' => __('material.material')]);
            return jsonResponse(true, 201, $message, $extra);
        }
        catch(\Exception $e) {
            \DB::rollBack();
            return jsonResponse(true, 207, __('message.server_error') . $e->getMessage());
        }
    }
public function store ( Request $ request ) { $ inputs = $ request -> all ( ) ; $ validation = ( new Material ) -> validation ( $ inputs ) ; if ( $ validation -> fails ( ) ) { return jsonResponse ( false , 206 , $ validation -> getMessageBag ( ) ) ; } try { \ DB :: beginTransaction ( ) ; if ( $ request -> hasFile ( 'image' ) ) { $ inputs [ 'image' ] = uploadImg ( $ request , 'image' , env ( 'MATERIAL_PATH' ) ) ; } $ inputs [ 'created_by' ] = authId ( ) ; ( new Material ) -> store ( $ inputs ) ; \ DB :: commit ( ) ; $ extra = [ 'redirect' => route ( 'material.index' ) ] ; $ message = __ ( 'message.created' , [ 'attr' => __ ( 'material.material' ) ] ) ; return jsonResponse ( true , 201 , $ message , $ extra ) ; } catch ( \ Exception $ e ) { \ DB :: rollBack ( ) ; return jsonResponse ( true , 207 , __ ( 'message.server_error' ) . $ e -> getMessage ( ) ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .
// image upload code start // image upload code end