I'm tryng to built a controller for a newsletter, her is my code:
Controller
public function postNews(Request $request, $user) {
$this->validate($request, [ 'email' => 'required | email' ]);
$user = User::findOrFail($id);
$data = array(
'email' => $request->email);
$token = $request->input('g-recaptcha-response');
if (strlen($token) > 0 ) {
Mail::send('emails.newsletter', $data, function( $message ) use ($data) {
$message->from($data['email']);
$message->to($user->email, $user->name)->subject('A-Studio News Letter');
//$message->subject($data['subject']);
});
Session::flash('success', 'Grazie per esserti iscritto alla nostra news letter!');
return view('blog.posts')->withPosts($posts);
}else {
return view('pages.nobot');
}
}
Route
Route::post('posts/{user}', ['uses' => 'BlogController@postNews', 'as' => 'blog.posts']);
Response MethodNotAllowedHttpException in RouteCollection.php line 218:
Any idea?
Thank you.
'posts/{var}'
? If it's defined before yourPOST
route it'll overwrite it and you get aMethodNotAllowedHttpException
because that route is not formatted correctly. – Roemerblog.post
route. – Alexey Mezenin{user}
? When sending this post what do you do to that{user}
variable in your route? – Michel