app/Http/Controllers/Admin/EssayAssignmentsController.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)
    {
        $validator = Validator::make($request->all(), [
            'assignment_num'    => ['required', 'integer', 'unique:essay_assignments'],
            'tutor_id'          => ['nullable', 'integer'],
            'student_id'        => ['nullable', 'integer'],
            'topic'             => ['required', 'string'],
            'description'       => ['required', 'string'],
            'file_format'       => ['nullable', 'string'],
            'price_owed'        => ['nullable', 'integer'],
            'paid_to_tutor'     => ['nullable', 'integer'],
            'date_assigned'     => ['nullable', 'date'],
            'date_completed'    => ['nullable', 'date'],
            'date_due'          => ['nullable', 'date'],
            'status_id'         => ['nullable', 'integer'],
        ]);
        if ($validator->fails())
        {
            $request->session()->flash('error', $validator->messages()->first());
            $tutors = Role::find(config('global.TUTOR_ROLE_ID'))->users()->get();
            $students = Role::find(config('global.STUDENT_ROLE_ID'))->users()->get();
            $a_num = EssayAssignment::all()->last()['assignment_num'] + 1;
            $essay_statuses = EssayStatus::all();
            $data = [
                'a_num'      => $a_num,
                'tutors'    => $tutors,
                'students'  => $students,
                'statuses'  => $essay_statuses,
            ];
            return view('admin.essayassignments.create')->with('data', $data);
        }
        $data = $request->all();
        $assignment = EssayAssignment::create([
            'assignment_num'        => $data['assignment_num'],
            'tutor_id'              => $data['tutor_id'],
            'student_id'            => $data['student_id'],
            'topic'                 => $data['topic'],
            'description'           => $data['description'],
            'format'                => $data['file_format'],
            'paid'                  => $data['paid_to_tutor'],
            'owed'                  => $data['price_owed'],
            'date_assigned'         => $data['date_assigned'],
            'date_completed'        => $data['date_completed'],
            'date_due'              => $data['date_due'],
            'status_id'             => $data['status_id'],
        ]);
        if ($assignment == NULL)
        {
            $request->session()->flash('error', "There was an error creating the homework assignment");
            $tutors = Role::find(config('global.TUTOR_ROLE_ID'))->users()->get();
            $students = Role::find(config('global.STUDENT_ROLE_ID'))->users()->get();
            $a_num = EssayAssignment::all()->last()['assignment_num'] + 1;
            $essay_statuses = EssayStatus::all();
            $data = [
                'a_id'      => $a_num,
                'tutors'    => $tutors,
                'students'  => $students,
                'statuses'  => $essay_statuses,
            ];
            return view('admin.essayassignments.create')->with('data', $data);
        }
        $request->session()->flash('success', "The homework assignment has been created successfully");
        $essay_assignments = EssayAssignment::has('students')->has('tutors')->get();
        $essay_statuses = EssayStatus::all();
        $data = [
            'essay_assignments' => $essay_assignments,
            'statuses'          => $essay_statuses,
            'old'               => [
            'a_id'              => $data['assignment_num'],
            's_name'            => "",
            't_name'            => "",
            'topic'             => $data['topic'],
            'status'            => $data['status_id'],
            'paid_to_tutor'     => $data['paid_to_tutor'],
            'price_owed'        => $data['price_owed'],
            'a_date_from'       => $data['date_assigned'],
            'a_date_to'         => $data['date_assigned'],
            'c_date_from'       => $data['date_completed'],
            'c_date_to'         => $data['date_completed'],
            ],
        ];
        return view('admin.essayassignments.index')->with('data', $data);
    }
public function store ( Request $ request ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 'assignment_num' => [ 'required' , 'integer' , 'unique:essay_assignments' ] , 'tutor_id' => [ 'nullable' , 'integer' ] , 'student_id' => [ 'nullable' , 'integer' ] , 'topic' => [ 'required' , 'string' ] , 'description' => [ 'required' , 'string' ] , 'file_format' => [ 'nullable' , 'string' ] , 'price_owed' => [ 'nullable' , 'integer' ] , 'paid_to_tutor' => [ 'nullable' , 'integer' ] , 'date_assigned' => [ 'nullable' , 'date' ] , 'date_completed' => [ 'nullable' , 'date' ] , 'date_due' => [ 'nullable' , 'date' ] , 'status_id' => [ 'nullable' , 'integer' ] , ] ) ; if ( $ validator -> fails ( ) ) { $ request -> session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; $ tutors = Role :: find ( config ( 'global.TUTOR_ROLE_ID' ) ) -> users ( ) -> get ( ) ; $ students = Role :: find ( config ( 'global.STUDENT_ROLE_ID' ) ) -> users ( ) -> get ( ) ; $ a_num = EssayAssignment :: all ( ) -> last ( ) [ 'assignment_num' ] + 1 ; $ essay_statuses = EssayStatus :: all ( ) ; $ data = [ 'a_num' => $ a_num , 'tutors' => $ tutors , 'students' => $ students , 'statuses' => $ essay_statuses , ] ; return view ( 'admin.essayassignments.create' ) -> with ( 'data' , $ data ) ; } $ data = $ request -> all ( ) ; $ assignment = EssayAssignment :: create ( [ 'assignment_num' => $ data [ 'assignment_num' ] , 'tutor_id' => $ data [ 'tutor_id' ] , 'student_id' => $ data [ 'student_id' ] , 'topic' => $ data [ 'topic' ] , 'description' => $ data [ 'description' ] , 'format' => $ data [ 'file_format' ] , 'paid' => $ data [ 'paid_to_tutor' ] , 'owed' => $ data [ 'price_owed' ] , 'date_assigned' => $ data [ 'date_assigned' ] , 'date_completed' => $ data [ 'date_completed' ] , 'date_due' => $ data [ 'date_due' ] , 'status_id' => $ data [ 'status_id' ] , ] ) ; if ( $ assignment == NULL ) { $ request -> session ( ) -> flash ( 'error' , " There was an error creating the homework assignment " ) ; $ tutors = Role :: find ( config ( 'global.TUTOR_ROLE_ID' ) ) -> users ( ) -> get ( ) ; $ students = Role :: find ( config ( 'global.STUDENT_ROLE_ID' ) ) -> users ( ) -> get ( ) ; $ a_num = EssayAssignment :: all ( ) -> last ( ) [ 'assignment_num' ] + 1 ; $ essay_statuses = EssayStatus :: all ( ) ; $ data = [ 'a_id' => $ a_num , 'tutors' => $ tutors , 'students' => $ students , 'statuses' => $ essay_statuses , ] ; return view ( 'admin.essayassignments.create' ) -> with ( 'data' , $ data ) ; } $ request -> session ( ) -> flash ( 'success' , " The homework assignment has been created successfully " ) ; $ essay_assignments = EssayAssignment :: has ( 'students' ) -> has ( 'tutors' ) -> get ( ) ; $ essay_statuses = EssayStatus :: all ( ) ; $ data = [ 'essay_assignments' => $ essay_assignments , 'statuses' => $ essay_statuses , 'old' => [ 'a_id' => $ data [ 'assignment_num' ] , 's_name' => " " , 't_name' => " " , 'topic' => $ data [ 'topic' ] , 'status' => $ data [ 'status_id' ] , 'paid_to_tutor' => $ data [ 'paid_to_tutor' ] , 'price_owed' => $ data [ 'price_owed' ] , 'a_date_from' => $ data [ 'date_assigned' ] , 'a_date_to' => $ data [ 'date_assigned' ] , 'c_date_from' => $ data [ 'date_completed' ] , 'c_date_to' => $ data [ 'date_completed' ] , ] , ] ; return view ( 'admin.essayassignments.index' ) -> with ( 'data' , $ data ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .