Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am creating web site. In this web site, I have created a Registration Form. User can Input details and when user clicks Submit button all the data save into the database. Here is my saveInvoice function. In my view page I have used saveInvoice as my action. Then I used request inputs in this function.

public function saveInvoice(Request $request)
    {
        if (Auth::user())
        {
            $settings = Setting::find(1);
            $invoiceNo=$settings->invoiceprefix.''.str_pad($settings->invoiceno, $settings->invoicepadding, 0, STR_PAD_LEFT);

            $invoice= new Invoice();
            $invoice->invoicereference=$invoiceNo;
            $invoice->firstname=$request->fname;
            $invoice->lastname=$request->lname;

            $invoice->save();

            $settings->invoiceno=$settings->invoiceno+1;
            $settings->update();

            if($invoice == null){
                return redirect()->back()->with('msg','invalid request');
            }
            else{
                return redirect()->route('invoice.preview',$invoiceNo);
            }
        }

    }

But , Now I want to create another function called sendemail. In this function I want to use user inputs which user has filled in that registration form. Can I get those request inputs from this above function or is there a another method ??

public function sendemail(Request $request) {
$invoiceNo = $request->input('invoiceNo');
            $fname = $request->input('fname');
            $Qty = $request->input('Qty');
            $price = $request->input('price');
            $sendemail = $request->input('email');

            $data = [];
            $data['invoiceNo'] = $invoiceNo;
            $data['fname'] = $fname;
            $data['Qty'] = $Qty;
            $data['price'] = $price;
            $data['sendemail'] = $sendemail;

            Mail::send(['text' => 'mail'], $data, function ($message) use ($data) {
                $message->to($data["sendemail"], 'TicketBooker')->subject
                ('CheapEfares Air Ticket');
                $message->from('kistlakall@gmail.com', 'CheapEfares');
            });
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
145 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can call sendemail function within saveInvoice function and then pass the Request object to sendemail function like

public function saveInvoice(Request $request){
//save invoice code

if($invoice == null){
  return redirect()->back()->with('msg','invalid request');
}
else{
  $this->sendemail(Request $request);
  return redirect()->route('invoice.preview',$invoiceNo);
}
}

I am assuming both the functions are in same class or one class is extending other class


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...