app/Http/Controllers/Admin/TutorAssignmentsController.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(), [
            'tutor_val'     => ['required', 'integer'],
            'student_val'   => ['required', 'integer'],
            'tpay_value'    => ['required', 'string'],
            'spay_value'    => ['required', 'string'],
            'subjects'      => ['required', 'Array'],
            'status'        => ['required', 'integer'],
        ]);
        if ($validator->fails())
        {
            session()->flash('error', $validator->messages()->first());
            return redirect()->route('admin.tutorassignments.create');
        }
        $data = $request->all();
        $assignment = Assignment::create([
            'tutor_id'      => $data['tutor_val'],
            'student_id'    => $data['student_val'],
            'base_wage'     => $data['tpay_value'],
            'base_invoice'  => $data['spay_value'],
            'active'        => $data['status'],
        ]);
        if ($assignment == NULL)
        {
            session()->flash('error', "There is an error creating the assignment!");
            return redirect()->route('admin.tutorassignments.create');
        }
        foreach($data['subjects'] as $subject)
        {
            $assignment->subjects()->attach($subject);
        }
        $assignment->save();
        Notification::addInformation(Auth::User()->id, $data['student_val'], "Tutor assigned"
            , "You have been assigned a tutor for tutoring.");
        Notification::addInformation(Auth::User()->id, $data['tutor_val'], "Student assigned"
            , "You have been assigned a student for tutoring.");   
        ActivityLog::log_activity(Auth::User()->id, "Tutor Assigned", "A tutor is assigned to a student.");
        $tutor_mail = Broadcast::where('id', 4)->first();
        $subject = $tutor_mail->subject;
        $message = $tutor_mail->content;
        $tutor = User::where('id', $data['tutor_val'])->first();
        $replace_info = Array(
                        'TUTOR_NAME' => $tutor->fname .' ' . $tutor->lname, 
                    );
        foreach($replace_info as $rep_key => $rep_text) {
            $message = str_replace('@'.$rep_key.'@', $rep_text, $message);
        }
        Mail::to($tutor->email)->send(new SendMail([
            'subject'   => $subject,
            'message'   => $message
        ]));
        session()->flash('success', "The assignment has been created successfully");
        return redirect()->route('admin.tutorassignments.index');
    }
public function store ( Request $ request ) { $ validator = Validator :: make ( $ request -> all ( ) , [ 'tutor_val' => [ 'required' , 'integer' ] , 'student_val' => [ 'required' , 'integer' ] , 'tpay_value' => [ 'required' , 'string' ] , 'spay_value' => [ 'required' , 'string' ] , 'subjects' => [ 'required' , 'Array' ] , 'status' => [ 'required' , 'integer' ] , ] ) ; if ( $ validator -> fails ( ) ) { session ( ) -> flash ( 'error' , $ validator -> messages ( ) -> first ( ) ) ; return redirect ( ) -> route ( 'admin.tutorassignments.create' ) ; } $ data = $ request -> all ( ) ; $ assignment = Assignment :: create ( [ 'tutor_id' => $ data [ 'tutor_val' ] , 'student_id' => $ data [ 'student_val' ] , 'base_wage' => $ data [ 'tpay_value' ] , 'base_invoice' => $ data [ 'spay_value' ] , 'active' => $ data [ 'status' ] , ] ) ; if ( $ assignment == NULL ) { session ( ) -> flash ( 'error' , " There is an error creating the assignment! " ) ; return redirect ( ) -> route ( 'admin.tutorassignments.create' ) ; } foreach ( $ data [ 'subjects' ] as $ subject ) { $ assignment -> subjects ( ) -> attach ( $ subject ) ; } $ assignment -> save ( ) ; Notification :: addInformation ( Auth :: User ( ) -> id , $ data [ 'student_val' ] , " Tutor assigned " , " You have been assigned a tutor for tutoring. " ) ; Notification :: addInformation ( Auth :: User ( ) -> id , $ data [ 'tutor_val' ] , " Student assigned " , " You have been assigned a student for tutoring. " ) ; ActivityLog :: log_activity ( Auth :: User ( ) -> id , " Tutor Assigned " , " A tutor is assigned to a student. " ) ; $ tutor_mail = Broadcast :: where ( 'id' , 4 ) -> first ( ) ; $ subject = $ tutor_mail -> subject ; $ message = $ tutor_mail -> content ; $ tutor = User :: where ( 'id' , $ data [ 'tutor_val' ] ) -> first ( ) ; $ replace_info = Array ( 'TUTOR_NAME' => $ tutor -> fname . ' ' . $ tutor -> lname , ) ; foreach ( $ replace_info as $ rep_key => $ rep_text ) { $ message = str_replace ( '@' . $ rep_key . '@' , $ rep_text , $ message ) ; } Mail :: to ( $ tutor -> email ) -> send ( new SendMail ( [ 'subject' => $ subject , 'message' => $ message ] ) ) ; session ( ) -> flash ( 'success' , " The assignment has been created successfully " ) ; return redirect ( ) -> route ( 'admin.tutorassignments.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// Here you can define keys for replace before sending mail to Student