Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
154 views
in Technique[技术] by (71.8m points)

php - How To Use Function Variables With Another Function

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('[email protected]', 'CheapEfares');
            });
}
See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...