app/Api/V1/Controllers/GradeController.php
/**
     * create new grade
     *
     * @param Request $request
     * @return Grade
     * @throws ValidationException
     */
create new grade
@param Request $request
@return Grade
@throws ValidationException
create new grade @param Request $request @return Grade @throws ValidationException
public function store(Request $request)
    {
        $this->validate($request, [
            'level' => 'required|unique:grades,level',
            'description' => 'string|nullable'
        ], ['level.unique' => 'Grade already exists']);
        $data = $request->only('level', 'description');
        $grade = new Grade($data);
        if ($grade->save()) {
            return $grade;
        }
        throw new StoreResourceFailedException('Grade couldn\'t be stored');
    }
public function store ( Request $ request ) { $ this -> validate ( $ request , [ 'level' => 'required|unique:grades,level' , 'description' => 'string|nullable' ] , [ 'level.unique' => 'Grade already exists' ] ) ; $ data = $ request -> only ( 'level' , 'description' ) ; $ grade = new Grade ( $ data ) ; if ( $ grade -> save ( ) ) { return $ grade ; } throw new StoreResourceFailedException ( 'Grade couldn\'t be stored' ) ; }
create new grade
 @param Request $request
 @return Grade
 @throws ValidationException
create new grade @param Request $request @return Grade @throws ValidationException