I have created a form, upon its submission it goes to email id which is stored in Laravels mail function. But I want to send same email to multiple people whose email-id are stored in database. Here is my code:
Routes:
Route::get('contactform', 'ClientsController@display1');
Route::post('contactform', 'ClientsController@contact');
My controller:
public function display(){
$data = Input::get('agree');
$count = count ($data);
if($count){
return $this->contact( $data,$count);
}
else{
echo "Select At least one email-id.";
return view('clientinfo.backtoprev');
}
}
public function display1(){
return view('contactform');
}
public function contact($data,$count){
$input = Input::only('name', 'email', 'msg');
$validator = Validator::make($input,
array(
'name' => 'required',
'email' => 'required|email',
'msg' => 'required',
)
);
if ($validator->fails())
{
return Redirect::to('contact')->with('errors', $validator->messages());
} else {
Mail::send('contactemail', $input, function($message) use($data)
{
$message->from('your@email.address', 'Your Name');
$message->to( $data);
});
return view('clientinfo.display', compact('data','count'));
}
}
here is my view "Contactform"
{!! Form::open(array('action' => 'ClientsController@contact','method' => 'post','name'=>'f1' , 'id'=>'form_id'))!!}
@if(Session::has('errors'))
<div class="alert alert-warning">
@foreach(Session::get('errors')->all() as $error_message)
<p>{{ $error_message }}</p>
@endforeach
</div>
@endif
//My fields, name & message
{!! Form::close() !!}
From the "display" method i'm passing two variables $data and $count to contact method, but after filling form and hitting submit error comes as
Missing argument 1 for App\Http\Controllers\ClientsController::contact()
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire