i'am trying to send a Mail with laravel after the registration , basically it's working , but when i added the name of the doctor into the Mail i got this error : Trying to get property 'Nom' of non-object , probably it doesn't know the "Name" of the doctor.
Thank you for your Help
The Doctor Controller :
public function ajouter (Request $request) {
$this->validate($request, [
'n' => 'required',
'p' => 'required' ,
'adresse' => 'required',
'mail' => 'required|email',
'mdp' => 'required|min:4',
'spec' => 'required',
'region' => 'required',
'ville'=>'required',
'photo'=> 'image|nullable|max:3999'
]);
$medecin= new doc() ;
$medecin->Nom= $request->input('n');
$medecin->Prénom =$request->input('p');
$medecin->Spécialité=$request->input('spec');
$medecin->Adresse_Cabinet=$request->input('adresse');
$id_ville=$request->input('region');
$medecin->Ville=vil::find($id_ville)->Ville;
$medecin->Délégation=$request->input('ville');
if($request->hasFile('photo')){
// Get filename with th extension
$file = $request->file('photo');
$extension=$file->getClientOriginalExtension();
$fileNameToStore=time().'.'.$extension;
$file->move('assets/img/uploads/',$fileNameToStore);
}
else {
$fileNameToStore =('noimage.png');
}
$medecin->photo=$fileNameToStore;
$medecin->Login=$request->input('mail');
$medecin->Password=Hash::make($request->input('mdp'));
$medecin->save();
Mail::to($request->input('mail'))->send(new WelcomeDoctorMail($medecin));
return redirect()->back()->withSuccess('medecin ajouter' ) ;
}
The Mail controller :
public $medecin;
/**
* Create a new message instance.
*
* #return void
*/
public function __construct(doc $medecin)
{
$this->doc = $medecin ;
}
public function build()
{
return $this->markdown('emails.welcome-doctor');
}
}
The Mail view :
#component('mail::message')
# Bienvenue
Merci {{$medecin->Nom}} de vous etes inscrit sur notre application.
Cordialement
Thanks,<br>
{{ config('app.name') }}
#endcomponent
You can use the with() function with an array as the first argument to specify what you want to access in the mail markup when returning from the build() function.
Like this:
public function build()
{
return $this->markdown('emails.welcome-doctor')
->with([
'medecin' => $this->doc
]);
}
EDIT: According to the documentation (https://laravel.com/docs/7.x/mail#view-data) you can access the variable directly if it's set to public in the class that extends Mailable. So you should be able to access $doc within the markup (not $medecin).
EDIT 2: I now see that you have defined public $medecin but you are trying to save the constructors parameter value in $this->doc which is not defined in the class that extends Mailable class nor used in the markdown. You could solve all your problems according to the documentation, by just changing $this->doc = $medecine to $this->medecine = $medecine.
first make sure the name inserted correctly into database ,
if it's correct try to access it like an array
#component('mail::message')
# Bienvenue
Merci {{$medecin['Nom']}} de vous etes inscrit sur notre application.
Cordialement
Thanks,<br>
{{ config('app.name') }}
#endcomponent
Related
I struggle to send a mail inside a botman reply.
I use mailhog, with botman 2.0 and laravel 5.7.
I've tested mailhog with simple php code , it work.
Here my env file config :
MAIL_DRIVER=smtp
MAIL_HOST=localhost
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
The conversation start here :
<?php
namespace App\Conversations\SASI\CreationTicket;
//use Validator;
use Illuminate\Support\Facades\Validator;
use BotMan\BotMan\Messages\Incoming\Answer;
use BotMan\BotMan\Messages\Conversations\Conversation;
use App\Conversations\SASI\CreationTicket\EndTicketResume;
class EndTicket extends Conversation
{
public function askProblem()
{
$this->ask('Décrivez succintement votre problème :', function(Answer $answer) {
$this->bot->userStorage()->save([
'problem' => $answer->getText(),
]);
$this->askEmail(); //passe à la fonction suivante
});
}
public function askEmail()
{
$this->ask('Quel est votre email?', function(Answer $answer) {
$validator = Validator::make(['email' => $answer->getText()], [
'email' => 'email',
]);
if ($validator->fails()) {
return $this->repeat('Cette email ne semble pas valide. Entrez un email valide.');
}
$this->bot->userStorage()->save([
'email' => $answer->getText(),
]);
$this->askMobile();
});
}
public function askMobile()
{
$this->ask('Quel est votre numéro pro?', function(Answer $answer) {
$this->bot->userStorage()->save([
'mobile' => $answer->getText(),
]);
$this->say('Merci');
//renvoi a une autre conversation app\Conversations\SelectServiceConversation.php
$this->bot->startConversation(new EndTicketResume());
});
}
public function run()
{
$this->askProblem();
}
}
As you can see the bot say "Merci" (thanks) and go to another conversation. If add my mail code the bot stop before he say "Merci"
So the next conversation :
<?php
namespace App\Conversations\SASI\CreationTicket;
use Illuminate\Support\Facades\Mail;
use BotMan\BotMan\Messages\Conversations\Conversation;
class EndTicketResume extends Conversation
{
public function confirmTicket()
{
$user = $this->bot->userStorage()->find();
$message = '------------------------------------------------ <br>';
$message .= 'Probleme : '.$user->get('problem').'<br>';
$message .= 'Email : '.$user->get('email').'<br>';
$message .= 'Tel : '.$user->get('mobile').'<br>';
$message .= '------------------------------------------------';
$this->say('Votre demande va être envoyé. <br><br>'.$message);
$email = $user->get('email');
$data = [
'first' => 'test',
'last' => 'TEST'
];
// send email with details
Mail::send('emails.justshoot', $data, function($message) use ($email) {
$message->subject('Welcome');
$message->from($email, 'Just Shoot Upload');
$message->to('myemail#gmail.com')->cc('test#gmail.com');
});
}
/**
* Start the conversation.
*
* #return mixed
*/
public function run()
{
$this->confirmTicket();
}
}
If I remove this
Mail::send('emails.justshoot', $data, function($message) use ($email) {
$message->subject('Welcome');
$message->from($email, 'Just Shoot Upload');
$message->to('myemail#gmail.com')->cc('test#gmail.com');
});
The bot say his last message, all is ok. But if I add this code , as I said previously, the bot won't even go to another conversation.
What I am doing wrong ?
Try to put the mail in a seperate function and different controller
you can debug using network tab in the console
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);
}
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);
}
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.
I have a table Languages with a language field and an image field. the CRU of CRUD is fine but the delete is firing the default validation. I have defined two validation files in Requests. One is AddNewLanguageRequest which contains:
public function rules()
{
return [
'language' => 'required|max:255|min:5',
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048'
}
and the other is EditLanguageRequest which contains
public function rules()
{
return [
'language' => 'required|max:255|min:5',
'image' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048'
];
}
I have a form which shows the language and the image to be deleted and as confirm button and so this form calls a route:
{!! Form::open( array('url'=>'deletelanguage/'.$lang->id)) !!}
The route calls the LanguageController
public function delete(Requests\EditLanguageRequest $request){
//is there an image? If so delete it
$lang = Language::find($request->id);
if (isset($lang->image))
{
if (Storage::exists($lang->image) )
{Storage::delete($lang->image);}
}
$lang->delete();
}
When I try it out I get a validation failure from the EditLanguageRequest.
How can I "turn off" validation for the delete action?
The problem was in this line:
public function delete(Requests\EditLanguageRequest $request
It was of course calling the request so changing it to
public function delete(Request $request)
solved it