如何将函数变量与另一个函数一起使用 [英] How To Use Function Variables With Another Function
问题描述
我正在创建网站.在此网站上,我创建了一个注册表.用户可以输入详细信息,当用户单击提交"按钮时,所有数据将保存到数据库中.这是我的saveInvoice函数.在我的视图页面中,我已使用saveInvoice作为操作.然后,我在此函数中使用了请求输入.
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);
}
}
}
但是,现在我想创建另一个名为sendemail的函数.在此功能中,我要使用用户输入了该注册表的用户输入.我可以从上面的函数中获取那些请求输入,还是有另一种方法?
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');
});
}
推荐答案
您可以在saveInvoice函数中调用sendemail函数,然后将Request对象传递给sendemail函数,例如
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
这篇关于如何将函数变量与另一个函数一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!