i've been working on a project and i'm stuck on mail error which states that i'm not able to send the email and the system couldn't find the path specified. Please do guide me about the error and help me fix the issue.
My Controller function:
public function orderSubmit(Request $request)
{
if (Cart::count() == 0){
session()->flash('message','Your Cart is Empty.');
session()->flash('type','warning');
return back();
}else{
$basic = BasicSetting::first();
$order['user_id'] = Auth::user()->id;
$order['order_number'] = strtoupper(Str::random(16));
$order['subtotal'] = Cart::subtotal();
$order['tax'] = Cart::tax();
$order['total'] = Cart::total();
$order['expire_time'] = Carbon::parse()->addMinutes($basic->expire_time);
$r = Order::create($order);
$cart = Cart::content();
foreach ($cart as $c){
$item['order_id'] = $r->id;
$item['product_id'] = $c->id;
$item['qty'] = $c->qty;
OrderItem::create($item);
$product = Product::findOrFail($c->id);
$product->stock = $product->stock - $c->qty;
$product->save();
}
$this->sendInvoice(Auth::user()->id,$r->id);
session()->flash('message','Order Submitted Successfully.');
session()->flash('type','success');
return redirect()->route('payment',$r->order_number);
}
}
My sendInvoic function:
public function sendInvoice($userId, $orderId)
{
$basic = BasicSetting::first();
$user = User::findOrFail($userId);
$userDetails = UserDetails::whereUser_id($userId)->first();
$order = Order::findOrFail($orderId);
$mail_val = [
'email' => $user->email,
'name' => $user->first_name.' '.$user->last_name,
'g_email' => $basic->email,
'g_title' => $basic->title,
'subject' => $basic->title.' '.'Order Invoice - '.$order->order_number,
];
$tomail = $mail_val['email'];
$toname = $mail_val['name'];
$frommail = $mail_val['g_email'];
$fromtitle = $mail_val['g_title'];
$fromsubject = $mail_val['subject'];
$items = null;
$logoUrl = asset('assets/images/logo.png');
$invoiceNumber = $order->order_number;
$invoiceDate = Carbon::parse($order->created_at)->format('F d, Y - h:i A');
$companyDetails = $basic->title."<br>".$basic->phone."<br>".$basic->address;
$userDetails = $userDetails->b_name."<br>".$userDetails->b_number."<br>".$userDetails->b_email;
$paymentUrl = route('payment',$order->order_number);
$subtotal = $basic->symbol.$order->subtotal;
$total = $basic->symbol.$order->total;
$totalTax = $basic->symbol.$order->tax;
$tax = $basic->tax;
$minute = $basic->expire_time;
$orderItem = OrderItem::whereOrder_id($orderId)->get();
foreach ($orderItem as $ot){
$productName = $ot->product->name;
$productPrice = $ot->product->current_price;
$productSub = $basic->symbol.($ot->qty*$productPrice);
$items .= '<tr class="item">
<td>
'.$productName.'
</td>
<td style="text-align:center">
'.$basic->symbol.$productPrice.'
</td>
<td style="text-align:center">
'.$ot->qty.'
</td>
<td>
'.$productSub.'
</td>
</tr>'; }*/
// Mail::send('emails.invoice', [
// 'logoUrl'=>$logoUrl,
// 'invoiceNumber'=>$invoiceNumber,
// 'invoiceDate' => $invoiceDate,
// 'companyDetails' => $companyDetails,
// 'userDetails' => $userDetails,
// 'paymentUrl' => $paymentUrl,
// 'subtotal' => $subtotal,
// 'total' => $total,
// 'totalTax' => $totalTax,
// 'tax' => $tax,
// 'items' => $items,
// 'minute' => $minute,
// ], function ($m) use ($mail_val) {
// $m->from($mail_val['g_email'], $mail_val['g_title']);
// $m->to($mail_val['email'], $mail_val['name'])->subject($mail_val['subject']);
// });
}
My function on button:
public function orderOverview()
{
$data['page_title'] = 'Order Overview';
$data['userDetails'] = UserDetails::whereUser_id(Auth::user()->id)->first();
return view('home.order-overview',$data);
}
Please advise to remove this error asap. Thanks
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire