No hint path defined for [mail] - laravel

so i was trying to send a mail with a pdf attachment but i get this error No hint path defined for [mail].
here is my buld function syntax
public function build()
{
$pdf = $this->pdf;
return $this->subject("Transaction Request")
->from('finance#vcass.org')
->attachData($pdf, 'transaction.pdf', [
'mime' => 'application/pdf'
])
->markdown('emails.usersingle', ['transaction' => $this->transaction]);
}
and here is my controller code
public function sendtransaction(Request $request)
{
$data = $request->all();
$id = $data['id'];
$transaction = Transaction::find($id);
$pdf = PDF::loadView('emails.usersingle', compact('transaction'));
$pdf = $pdf->output();
try {
Mail::to($data['email'])->send(new MailTransaction($transaction, $pdf));
return redirect()->back()->with('success', 'transaction sent to mail, check your mail');
} catch (\Swift_TransportException $e) {
return redirect()->back()->with('warning', 'Sorry mail couldnt be sent, please try again');
} catch (\Exception $e) {
dd($e);
}
}
please I need help on this fast!

Related

Laravel File Upload "Laminas\Diactoros\Exception\InvalidArgumentException"

Good day,
I have been running into this exception "Laminas\Diactoros\Exception\InvalidArgumentException: Invalid stream reference provided in file" while trying to upload a video file taken from the camera with react-native-image-picker. Now i ran into this same issue while trying to upload photos some days back till i switched from using "$file->move()" to using "Intervention Image". I dont really understand the error and need some help.
EDIT: I should also mention that when i used postman to upload, it was successful.
Thanks
public function save_verification_video(Request $request) {
/**
* 'file' => 'mimes:video/x-ms-asf,video/x-flv,video/mp4,application/x-mpegURL,video/MP2T,video/3gpp,video/quicktime,video/x-msvideo,video/x-ms-wmv,video/avi'
*/
try {
$validator = $this->validator($request->all(), [
'glam_id' => '',
]);
if ($validator['failed']) {
return \prepare_json(false, ['messages' => $validator['messages']],'',$status_code=200);
}
$data = $request->all();
if ($request->hasFile('body_video') || $request->hasFile('speech_video')) {
// $this->out->writeln("User ".$user->last_name);
$file = $request->file('body_video') ?? $request->file('speech_video');
$verification_type = ($request->hasFile('body_video')) ? 'body_video' : 'speech_video';
$path = public_path('/uploads/glams/'. $user->code . '/videos/'.$verification_type . '/');
File::makeDirectory($path, $mode=0777, true, true);
// $res = MediaUploader::fromFile($file)->upload();
$res = $file->move($path, $file->getClientOriginalName());
if ($res) {
return \prepare_json(true, [],\get_api_string('generic_ok'), $status_code=200);
}
else {
return \prepare_json(false, [],\get_api_string('file_not_ploaded'), $status_code=200);
}
}
else {
return \prepare_json(false, [],\get_api_string('no_videos'), $status_code=200);
}
}
catch(\Illuminate\Database\Eloquent\ModelNotFoundException $ex) {
return \prepare_json(false, [], \get_api_string('glam_not_found'));
}
catch(\Exception $ex) {
return \prepare_json(false, [],\get_api_string('error_occured').$ex->getMessage(), $status_code=200);
}
}

Object of class Illuminate\Routing\Redirector could not be converted to string. srmklive/laravel-paypal

I am currently working on a paypal checkout using paypal and https://github.com/srmklive/laravel-paypal. I'm using the express checkout which I modified it a little bit to fit the requirements of the my project. During testing it is working in a couple of tries, paypal show and payment executes properly but when I tried to run the exact same code. I get this error I don't know what it means.
I tried to check my routes if it all of the errors happens to my routes but all of it are working properly. I also tried dump and die like dd("check") just to check if its really going to my controller and it does. I did this in the method "payCommission" (this where the I think the error happens)
This is my route for the controller
api.php
Route::get('service/commissionfee/payment' , 'api\service\ExpressPaymentController#payCommission');
Route::get('paypal/ec-checkout-success', 'api\service\ExpressPaymentController#payCommissionSuccess');
ExpressPaymentController.php
<?php
namespace App\Http\Controllers\api\service;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Srmklive\PayPal\Services\ExpressCheckout;
class ExpressPaymentController extends Controller
{
protected $provider;
public function __construct()
{
try {
$this->provider = new ExpressCheckout();
}
catch(\Exception $e){
dd($e);
}
}
public function payCommission(Request $request)
{
$recurring = false;
$cart = $this->getCheckoutData($recurring);
try {
$response = $this->provider->setExpressCheckout($cart, $recurring);
return redirect($response['paypal_link']);
} catch (\Exception $e) {
dd($e);
return response()->json(['code' => 'danger', 'message' => "Error processing PayPal payment"]);
}
}
public function payCommissionSuccess(Request $request)
{
$recurring = false;
$token = $request->get('token');
$PayerID = $request->get('PayerID');
$cart = $this->getCheckoutData($recurring);
// ? Verify Express Checkout Token
$response = $this->provider->getExpressCheckoutDetails($token);
if (in_array(strtoupper($response['ACK']), ['SUCCESS', 'SUCCESSWITHWARNING'])) {
if ($recurring === true) {
$response = $this->provider->createMonthlySubscription($response['TOKEN'], 9.99, $cart['subscription_desc']);
if (!empty($response['PROFILESTATUS']) && in_array($response['PROFILESTATUS'], ['ActiveProfile', 'PendingProfile'])) {
$status = 'Processed';
} else {
$status = 'Invalid';
}
} else {
// ? Perform transaction on PayPal
$payment_status = $this->provider->doExpressCheckoutPayment($cart, $token, $PayerID);
$status = $payment_status['PAYMENTINFO_0_PAYMENTSTATUS'];
}
return response()->json(['success' => "payment complete"]);
}
}
private function getCheckoutData($recurring = false)
{
$data = [];
$order_id = 1;
$data['items'] = [
[
'name' => 'Product 1',
'price' => 9.99,
'qty' => 1,
],
];
$data['return_url'] = url('api/paypal/ec-checkout-success');
// !
$data['invoice_id'] = config('paypal.invoice_prefix').'_'.$order_id;
$data['invoice_description'] = "Commission Fee payment";
$data['cancel_url'] = url('/');
$total = 0;
foreach ($data['items'] as $item) {
$total += $item['price'] * $item['qty'];
}
$data['total'] = $total;
return $data;
}
}
Error I am getting
Object of class Illuminate\Routing\Redirector could not be converted to string
Thank you in advance
you may just go to the config/paypal.php and edit
'invoice_prefix' => env('PAYPAL_INVOICE_PREFIX', 'Life_saver_'),
you may use _ underline in this like Life_saver_, dont forget use underline at the end too.

Sending email passing name in laravel

I'm trying to send an email to a user by entering his name and I look for the user's email with this name, but it does not work, the success message appears but in my email I receive nothing. what am I doing wrong?
if(User::where('name', '=', $destinatario)->exists()){
$exists = DB::table('users')
->select('email')
->where('name', $destinatario)
->get();
Mail::to($exists)->send(new TestEmail($remetente, $nome, $assunto, $exists, $mensagem));
return back()->with('sucess', 'Message sent!');
}else{
return back()->with('error', 'User does not exist!');
}
Mailable:
public function __construct($remetente, $nome, $assunto, $destinatario, $data)
{
$this->remetente = $remetente;
$this->nome = $nome;
$this->assunto = $assunto;
$this->destinatario = $destinatario;
$this->data = $data;
}
public function build()
{
//$address = 'gabriel.jg04#gmail.com';
$subject = 'E-mail de Usuário';
$name = 'Juelito';
return $this->view('emails.test',['texto'=>$this->data])
->from($this->remetente, $this->nome)
->replyTo($this->destinatario, $name)
->subject($this->assunto);
}
Problem is with get(). get() returns collection of users.
But your mailable expect single user.
If you want to send mail to one person you could do like that:
$user = User::where('name', '=', $destinatario)->first();
if($user){
Mail::to($user)->send(new TestEmail($remetente, $nome, $assunto, $user, $mensagem));
return back()->with('sucess', 'Message sent!');
} else {
return back()->with('error', 'User does not exist!');
}
If you want to send mail to multiple persons you could do like that:
$users = User::where('name', '=', $destinatario)->get();
if($users->count()){
foreach($users as $user){
Mail::to($user)->send(new TestEmail($remetente, $nome, $assunto, $user, $mensagem));
}
return back()->with('sucess', 'Message sent!');
} else {
return back()->with('error', 'User does not exist!');
}
Mailable:
public function __construct($remetente, $nome, $assunto, $destinatario, $data)
{
$this->remetente = $remetente;
$this->nome = $nome;
$this->assunto = $assunto;
$this->destinatario = $destinatario;
$this->data = $data;
}
public function build()
{
return $this->view('emails.test', ['texto' => $this->data])
->from($this->remetente, $this->nome)
->replyTo($this->destinatario->email, $this->desctinario->name)
->subject($this->assunto);
}

ErrorException Undefined variable: code (View: C:\wamp\www\secureserver\app\views\emails\adminverify.blade.php)

I have been toiling around to no avail of Solutions Please help. It seems my View cannot read the $code and $user variable respectively from my Controller
Here is the part of my controller that the $code and $user Variables are been instantiated respectively:
UserController.php
public function varifyMail($code){
if(User::where('varification_code','=',$code)->update(['varification_status'=>1])){
return Redirect::route('login')
->with('success', 'Account varified.');
}else{
return Redirect::route('login')
->with('error', 'Varification Failed.Try again');
}
);
$validation = Validator::make(Input::all(),$rules);
if($validation->fails()){
return Redirect::route('login')
->with('error', 'Invalid Email Address. Try again.');
}else{
$code = str_random(25);
$userUpdate = ['recovery_code' => $code];
User::where('email','=',Input::get('email'))->update($userUpdate);
$data = ['code'=>$code];
//send mail
Mail::send('emails.recover',$data,function($message){
$message->to(Input::get('email'))->subject('Recover Your Account.');
});
return Redirect::route('login')
->with('success', 'Request Send successfully.Please Recover Your Account.');
//return User::where('email','=',Input::get('email'))->get();
}
Auth::login($user);
return View::make('users.edit')
->with('title','Update Cridentials')
->with('user',User::where('id','=',$user->id)->first());
}else{
return Redirect::route('login')
->with('error', 'Recovery Failed.Try again');
}
And this is my view:
Adminverify.blade.php
<div class="header-content"><webversion>Web Version</webversion><span class="hide"> | <preferences lang="en">Update preferences</preferences> | </span>
But whenever I try using it it get this error:
ErrorException
Undefined variable: code (View: C:\wamp\www\secureserver\app\views\emails\adminverify.blade.php)
Any Help will be highly Appreciated Thanks!
Thanks for your prompt response but it happens to be that it did not work but here is my entire Controller with the Varify changed to Verify as cadmium suggested so we can be sure what exactly could be the challenge.
class UserController extends BaseController {
private function verify($email){
$verify = User::where('email','=',$email)->first();
if(! is_null($verify)){
if($verify->role_id==2){
return $verify->distributor_approve & $verify->varification_status;
}else{
return $verify->varification_status;
}
}else{
return 0;
}
}
/**
* login page
* #return void
*/
public function login()
{
return View::make('users.login')
->with('title', 'Log in');
}
/**
* process to login a user
* #return void
*/
public function doLogin()
{
$rules = array
(
'email' => 'required|email',
'password' => 'required'
);
$validation = Validator::make(Input::all(), $rules);
if($validation->fails())
return Redirect::route('login')
->withInput()
->withErrors($validation);
else
{
$credentials = array
(
'email' => Input::get('email'),
'password' => Input::get('password')
);
if($this->verify(Input::get('email')) && Auth::attempt($credentials))
{
Session::put('role', Auth::user()->role_id);
//return User::where('id','=',Auth::user()->id)->first();
if(User::where('id','=',Auth::user()->id)->first()->first_login == 0){
return Redirect::route('info.create',[Auth::user()->id]);
}
return Redirect::intended('/');
}
else
return Redirect::route('login')
->withInput()
->with('error', 'Error in Email Address or Password.');
}
}
/**
* logout a user
* #return void
*/
function logout()
{
Auth::logout();
Session::forget('role');
return Redirect::route('login')
->with('success', 'You have been logged out.');
}
public function show(){
$pages= Page::orderby('title')->get();
if(Auth::check()){
if(Auth::user()->role_id==1){
return View::make('public.pages.admin')
->with('title', "Home");
}
}
return View::make('public.pages.show')
->with('title', "Home")
->with('pages',$pages);
}
public function register()
{
return View::make('users.register')
->with('title', 'Register');
}
public function doRegister()
{
//return Input::all();
$rules = array
(
'username' => 'required|min:3|max:15',
'email' => 'required|email|unique:users',
'password' =>'Required|Confirmed',
'password_confirmation' =>'Required',
'role' => 'Required',
'agree' => 'Required',
'recaptcha_response_field' => 'required|recaptcha'
);
$validation = Validator::make(Input::all(), $rules);
if($validation->fails())
return Redirect::route('register')
->withInput()
->withErrors($validation);
else
{
if(Input::get('role')==3){
$user = new User;
$user->user_name = Input::get('username');
$user->email = Input::get('email');
$user->password = Hash::make(Input::get('password'));
$user->role_id = Input::get('role');
$code = str_random(25);
$user->varification_code = $code;
$data = ['username'=>Input::get('username'),'code'=>$code];
Mail::send('emails.validate',$data,function($message){
$message->to(Input::get('email'))->subject('Please Verify Your Email.');
});
if($user->save())
return Redirect::route('home')
->with('success', "Verify Your Account.");
else
return Redirect::back()->withInput()->withErrors($validation)->with('error', 'Some error occured. Try again.');
}else{
$user = new User;
$user->user_name = Input::get('username');
$user->email = Input::get('email');
$user->password = Hash::make(Input::get('password'));
$user->role_id = Input::get('role');
$user->distributor_status = 1;
$code = str_random(25);
$user->varification_code = $code;
$data = ['username'=>Input::get('username'),'code'=>$code];
Mail::send('emails.validate',$data,function($message){
$message->to(Input::get('email'))->subject('Please Verify Your Email.');
});
if($user->save())
return Redirect::route('home')
->with('success', "Request Send successfully.Please Verify Your Email.");
else
return Redirect::back()->withInput()->withErrors($validation)->with('error', 'Some error occured. Try again.');
}
}
}
public function edit(){
return View::make('users.edit')
->with('title','Update Cridentials')
->with('user',User::where('id','=',Auth::user()->id)->first());
}
public function update(){
$rules = array
(
'username' => 'required|min:3|max:15',
'password' =>'Required|Confirmed',
'password_confirmation' =>'Required'
);
$validation = Validator::make(Input::all(), $rules);
if($validation->fails())
return Redirect::back()
->withInput()
->withErrors($validation);
else
{
$userUpdate = ['user_name' => Input::get('username'),
'password'=>Hash::make(Input::get('password'))
];
if(User::find(Auth::user()->id)->update($userUpdate)){
Auth::logout();
Session::forget('role');
return Redirect::route('login')
->with('success', 'Your Cridentials Have Been Changed.');
}
else
return Redirect::back()->withInput()->withErrors($validation)->with('error', 'Some error occured. Try again.');
}
}
public function verifyMail($code){
if(User::where('varification_code','=',$code)->update(['varification_status'=>1])){
return Redirect::route('login')
->with('success', 'Account varified.');
}else{
return Redirect::route('login')
->with('error', 'Varification Failed.Try again');
}
}
public function passwordRecover(){
$rules = array
(
'email' => 'required|email'
);
$validation = Validator::make(Input::all(),$rules);
if($validation->fails()){
return Redirect::route('login')
->with('error', 'Invalid Email Address. Try again.');
}else{
$code = str_random(25);
$userUpdate = ['recovery_code' => $code];
User::where('email','=',Input::get('email'))->update($userUpdate);
$data = ['code'=>$code];
//send mail
Mail::send('emails.recover',$data,function($message){
$message->to(Input::get('email'))->subject('Recover Your Account.');
});
return Redirect::route('login')
->with('success', 'Request Send successfully.Please Recover Your Account.');
//return User::where('email','=',Input::get('email'))->get();
}
}
public function mailRecover($code){
$user = User::where('recovery_code','=',$code)->first();
if(! is_null($user)){
Auth::login($user);
return View::make('users.edit')
->with('title','Update Cridentials')
->with('user',User::where('id','=',$user->id)->first());
}else{
return Redirect::route('login')
->with('error', 'Recovery Failed.Try again');
}
}
/**
* Show a page
* #param string $pageUrl
* #return void
*/
public function pages($pageUrl = 'home')
{
try
{
$page = Page::where('url', '=', $pageUrl)->firstOrFail();
/*
if($page->id == 1) $layout = 'layouts.home';
else $layout = 'layouts.default';
*/
$layout = 'layouts.default';
return View::make('public.pages.publicShow')
->with('title', "$page->title")
->with('page', $page)
->with('layout', $layout);
}
catch(ModelNotFoundException $e)
{
return "Page not found.";
}
}
Somewhere in your code you need to have View::make("adminverify"). I don't see it in the code you've posted, but it's there somewhere. You need to pass the $code value to this view, like so:
View::make("adminverify")->with("code", "some code value");
Once you do that, the $code variable will be available in the template.

Laravel4 Doesnt show old::input()

New to laravel4 and cant get the basic things to work such as:
function doRegister() {
try {
$email = Input::get('email');
$type = Input::get('type'); // <-- Data from radio button
# Check if email exists
if ( User::where('email','=',$email)->count() > 0 ) {
# This account already exists
throw new Exception( 'This email already in use by someone else.' );
}
} catch (Exception $e) {
return Redirect::to('/')->withInput()->with('message', $e->getMessage() );
}
}
Now on the homepage controller (which is /) I cant read the value of Input::old('type');
and it returns empty. How come?
Try this instead:
function doRegister()
{
$rules = array('email' => 'required|email|unique:users');
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to('/')->withInput()>withErrors($validator);
}
else {
$email = Input::get('email');
$type = Input::get('type');
// Register...
}
}
You can retrieve validation errors using:
$errors->first('email');

Resources