laravel 5.4 Send Email error : Default value for parameters with a class type hint can only be NULL in CssSelectorConverter.php line 34 - laravel

I run code on local host send email success. But, I run code on Linux host send email error
This image error
My controller
public function vendorApprove($vendor_id)
{
//dd($vendor_id);
$approve = DB::table('vendor')->where('vid', '=', $vendor_id)->update(['active' => 1]);
$mail = DB::table('vendor as v')
->join('vendor_contact as vc', 'v.vid', '=', 'vc.vid')
->where('v.vid', '=', $vendor_id)
->first();
//dd($mail);
Mail::to($mail->email)->send(new VendorApproveMail($mail));
return redirect(route('admin.dashboard'))->with('success', 'Vendor Approve success');
}
And Mailable code
public function __construct($mail)
{
$this->mail = $mail;
}
public function build()
{
return $this->from(config('mail.username'))
->subject('Vendor Approve')
->markdown('admin.emails.approve', [
'url' => url( route('vendor.profile', $this->mail->vid )),
'name' => $this->mail->vcontName,
'email' => $this->mail->email,
'message' => 'The vendor your approved',
]);
}
If I comment //Mail::to($mail->email)->send(new VendorApproveMail($mail)); This code, it working
I think function send email not working

The formatting of the markdown must always be left.
This my markdown
This is the correct format.

Related

Call to a member function move() on null when update in laravel

I got this errror when trying to update data. If I update the image there's no error, but if I'm not it showing Call to a member function move() on null
This is my code:
public function update($id, Request $request)
{
$change = Profile::findorfail($id);
$before = $change->foto_profil;
$profile = [
'fullname' => $request['fullname'],
'phone' => $request['phone'],
'ttl' => $request['ttl'],
'foto_profil' => $before
];
$request->foto_profil->move(public_path().'/image', $before);
$change->update($profile);
return redirect('/profil');
}
You may determine if a file is present on the request using the hasFile() method :
if($request->hasFile('foto_profil')){
$request->foto_profil->move(public_path().'/image', $before);
}
See the documentation here
just add validation if photo exists in request
if($request->foto_profil) {
$request->foto_profil->move(public_path().'/image', $before);
}

Laravel sending e-mails to new registered users

I'm trying to send e-mails to new users. I made changes in my env. file. I am using a gmail.com mail service. I want to send e-mails to users including their name. Ex:
Hi John, your registration is succesful!
Here John part will be user name.
my code is here in RegistrationController:
protected function create(array $data)
{
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
$to_name = $data['name'];
$to_email= $data['email'];
$body =[];
$mailData=array('body'=>$body);
Mail::send('email.email-register', $mailData, function($message) use ($to_name, $to_email ){
$message->to($to_email, $to_name)->subject('Registration is succesfull!');
$message->from(env('MAIL_USERNAME'));
});
return $user;
}
Also i am using a mail template. I want to send user as variable to the view. How do i do that?
1- You need to run command php artisan make:mail RegisterMail
2- Add Library use App\Mail\RegisterMail;
Mail::to('YourEmail#gmail.com')->send(new RegisterMail($mailData));
3- Create a new Data Member in your App\Mail\RegisterMail.php Class
public $mailData;
public function __construct($mailData)
{
$this->mailData = $mailData;
}
4- Add this in your App\Mail\RegisterMail.php
public function build(){
return $this->from('youremail#gmail.com','your name')->replyTo('youremail#gmail.com')->subject($this->mailData['subject'])->view('email')->with('mailData',$this->mailData);
}

Route Model binding fails when using Form request

The Route model binding fails when I use the FormRequest to validate the request. To be more specific, when I try to access the parameters in the form request and give the following error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name:\"moniersa\"' in 'where clause'
(SQL: select count(*) as aggregate from `users` where `email` = a.monier2130#gmail.com and
`name:\"moniersa\"` <> {\"id\":5 and `email:\"a`.`monier2130#gmail`.`com\"` =
email_verified_at:null and `admin:1` = verified:0 and `created_at:\"2020-02-11 22:33:33\"` =
updated_at:\"2020-02-11 23:17:40\"})
The code of the update method:
public function update(User $user, UpdateUserRequest $request)
{
$data = $this->extract_data($request);
$user->update($data);
return response()->json(['data' => $user], 200);
}
The code of the rules function in the Update request:
public function rules()
{
return [
'name' => 'required|string|min:3|max:40',
'email' => 'required|email|unique:users,email,' . $this->user,
'password' => 'required|string|min:9|confirmed'
];
}
Whenever, I remove the User hint from the update method or $this->user from the update request file, everything works fine. Any clue about what is the problem is?
Route model binding means you do not need to use $user = User::findOrFail($user); anymore,
public function update(User $user, UpdateUserRequest $request)
{
$user = User::findOrFail($user);// this line is redundant, you can remove it.
$data = $this->extract_data($request);
$user->update($data);
return response()->json(['data' => $user], 200);
}

How can i edit and delete a page in laravel 5.2?

When i try to edit and delete an employee,an error will shows.
For delete
Missing argument 1 for App\Http\Controllers\Admin\CreateEmployeeController::deleteemployee()
For edit
Missing argument 1 for App\Http\Controllers\Admin\CreateEmployeeController::editemployee()
Methods:
public function editemployee($id)
{
$employee = CreateEmployee::where('id',$id)->get();
return view('app.admin.employee.editemployee',compact('employee'));
}
public function updateemployee(Request $request)
{
CreateEmployee::where('id',$request->id)->update(array('username'=>$request->username,'area'=>$request->area_name));
Session::flash('flash_notification', array('level' => 'success', 'message' => 'channel details updated successfully'));
return Redirect::action('Admin\CreateEmployeeController#addemployee',array('id' => $request->id));
}
public function deleteemployee($id)
{
$employee = CreateEmployee::where('id',$id)->get();
return view('app.admin.employee.deleteemployee',compact('employee'));
}
public function deleteconfirms($id)
{
$employee = CreateEmployee::where('id',$id)->delete();
Session::flash('flash_notification', array('level' => 'success', 'message' => 'employee deleted successfully'));
return Redirect::action('Admin\CreateEmployeeController#addemployee');
}
As I can see that your methods deleteemployee , deleteconfirms and editemployee are expecting the id field.
While in your route you are not using any "Route parameters" (for details see Route Parameters ).
So, change your routes to include Route Parameters as follows. where id represents employee_id
Route::get('edit-employee/{id}','CreateEmployeeController#editemp‌​loyee');
Route::post('update-employee','CreateEmployeeController#upd‌​ateemployee');
Route::get('delete-employee/{id}','CreateEmployeeController#delet‌​eemployee');
Route::post('delete-confirms/{id}','CreateEmployeeController#dele‌​teconfirms');

How to attach variable to reset password link view in laravel?

I am using laravel 5.2 where I need to sent an OTP code to reset password, though email is being sent with built in subject and limited message done by make:auth command but how to customize? I have tried to follow the link unfortunately I am unable to understand how i can use this to solve.
I customized the api like this
public function sendResetLinkEmail(Request $request)
{
$this->validateSendResetLinkEmail($request);
$broker = $this->getBroker();
$email = $request->input('email');
$userid = DB::table('users')->where('email','=',$email)->value('id');
$uniqueotp = "DIYA".uniqid();
$curr_timestamp = strtotime(date("Y-m-d H:i:s"));
$date = strtotime("+7 day", $curr_timestamp);
$expiry_otp = date('Y-m-d H:i:s',$date);
$ip_address = $request->ip();
DB::table('otp_users')->insert([
'user_id' => $userid,
'status' => 0,
'otp_code' => $uniqueotp,
'ipaddress'=>$ip_address,
'expires_at'=>$expiry_otp
]);
$response = Password::broker($broker)->sendResetLink(
$this->getSendResetLinkEmailCredentials($request),
$this->resetEmailBuilder()
);
switch ($response) {
case Password::RESET_LINK_SENT:
return $this->getSendResetLinkEmailSuccessResponse($request,$response);
case Password::INVALID_USER:
default:
return $this->getSendResetLinkEmailFailureResponse($response);
}
}
Any idea how I can achieve?
My required email message like this:
Hello, Tamaghna Banerjee Click here to reset your password:
Your OTP is: B16445512121
Reset Your Password through http://localhost/diya/public/password/reset/83baba9f61fc851b9d80b515415ec86c43b03b56b068e1888256db7a7831ba83?email=tamaghnabanerjee%40live.com

Resources