MethodNotAllowedHttpException Laravel - laravel

I'm having trouble with an error that I'm getting in laravel. When I run my code on localhost I don't have any issues, but when I placed laravel in demo live server which is server ('https') I get the MethodNotAllowedHttpException error.
Here's my code for my route
Route::post('post_reminder', function(){
$creds = array(
'email' => Input::get('email')
);
$rules = array(
'email' => 'required|email'
);
$messages = array(
'email' => 'The :attribute needs to be an real email'
);
$validator = Validator::make($creds, $rules,$messages);
if($validator->fails())
{
return Redirect::route('getReminder')->withErrors($validator);
}
else
{
return Password::remind($creds);
}
});
And here's the form code
<div id="reset_container">
{{ Form::open(array('url' => 'post_reminder')) }}
<h1 id="pass_recovery_text">Password Recovery Form</h1>
<p>
#if (Session::has('error'))
<li id="error">{{ trans(Session::get('reason')) }}</li>
#elseif (Session::has('success'))
<li id="error">An e-mail with the password reset has beensent.</li>
#endif
#foreach($errors->all() as $error)
<li id="error">{{ $error }}</li>
#endforeach
{{ Form::label('email', 'Please enter you email: ') }}
{{ Form::text('email','',array('id' => 'forgot')) }}
{{ Form::submit('Reset') }}<br /><br /><br />
{{ HTML::link('/', 'Have a account Sign-In', array('id' => 'sign-in')) }}
</p>
{{ Form::close() }}
</div>

<div id="reset_container">
{{ Form::open(array('url' => 'post_reminder','method' => 'post')) }}
<h1 id="pass_recovery_text">Password Recovery Form</h1>
<p>
#if (Session::has('error'))
<li id="error">{{ trans(Session::get('reason')) }}</li>
#elseif (Session::has('success'))
<li id="error">An e-mail with the password reset has beensent.</li>
#endif
#foreach($errors->all() as $error)
<li id="error">{{ $error }}</li> #endforeach
{{ Form::label('email', 'Please enter you email: ') }}
{{ Form::text('email','',array('id' => 'forgot')) }}
{{ Form::submit('Reset') }}
{{ HTML::link('/', 'Have a account Sign-In', array('id' => 'sign-in')) }} </p>
{{ Form::close() }}

Have you tried force the route to be served over https?
Route::post('post_reminder', array('https', function(){
$creds = array(
'email' => Input::get('email')
);
$rules = array(
'email' => 'required|email'
);
$messages = array(
'email' => 'The :attribute needs to be an real email'
);
$validator = Validator::make($creds, $rules,$messages);
if($validator->fails())
{
return Redirect::route('getReminder')->withErrors($validator);
}
else
{
return Password::remind($creds);
}
}));
Referencing to http://laravel.com/docs/4.2/routing here.

Related

Email Sending and Validation Failing in Laravel 5.4

I am creating a contact form using bootstrap3 build on Laravel 5.4. When I click the submit button, I expect an email to be sent to my inbox or if there are errors they should be validated on the back end and errors displayed at the top of the form. I am using Laravel collective to build the form, when I fill the form and click the submit button, the page only reloads and no validation happens or in case of correct input no email is sent. Please assist?
Form Section
<div class="col-sm-4 wow animated fadeInLeft">
<div id="success" class="col-sm-12">
#if(Session::has('success'))
<span class="alert alert-success" role="alert">
<strong> Success: </strong> {{ Session::get('success') }}
</span>
#endif
#if(count($errors) > 0)
<span class="alert alert-danger" role="alert">
<strong> Errors: </strong>
<ul>
#foreach($errors->all() as $error)
<li> {{ $error }} </li>
#endforeach
</ul>
</span>
#endif
</div>
{!! Form::open(array('route' => 'index.post', 'method' => 'POST','class' => 'contact-form')) !!}
{{ Form::text('name', null, array( 'placeholder' => 'Name...', 'class' => 'input', 'required' => ''))}}
{{ Form::email('email', null, array('placeholder' => 'Email Address...','class' => 'input', 'required' => ''))}}
{{ Form::textarea('message', null, array('placeholder' => 'Message...', 'class' => '', 'required' => 'input')) }}
{{ Form::submit('Submit') }}
{!! Form::close() !!}
</div>
Routes File
Route::post('/', 'PagesController#postIndex') ->name('index.post');
Route::get('/', 'PagesController#getIndex') ->name('pages.index');
PagesController
public function postIndex(Request $request){
$this->validate($request, array(
'name' => 'required|min:10',
'email' => 'required|email',
'message' => 'required|min:100'
));
$name = $request->name;
$data = array(
'name' => $request->name,
'email' => $request->email,
'bodymessage' => $request->message
);
Mail::send('emails.contact', $data, function($message) use ($data) {
$message->from($data['email']);
$message->to('info#pwebk.com');
});
Session::flash('success', 'Hello '.$name.', Your Form was successfully sent');
return redirect()->route('pages.index');
}
public function getIndex(){
return view('pages.welcome');
}

Alert Message not showing in Laravel 5.4

I have got a contact form that is build using Laravel 5.4, parsley.js and Bootstrap 3, it works fine but it does not display a success message at the top of the form on successful delivery of a message or display any errors in case there is an error. Please assist?
Contoller
public function postIndex(Request $request){
$this->validate($request, array(
'name' => 'required|min:10',
'email' => 'required|email',
'message' => 'required|min:100'
));
$name = $request->name;
$data = array(
'name' => $request->name,
'email' => $request->email,
'bodymessage' => $request->message
);
Mail::send('emails.contact', $data, function($message) use ($data) {
$message->from($data['email']);
$message->to('info#kapsol.com');
});
Session::flash('success', 'Hello $name, Your Form was successfully sent');
return redirect()->route('pages.index');
}
Index.blade.php
<div class="col-sm-4">
{!! Form::open(array('route' => 'index.post', 'class' => 'contact-form', 'data-parsley-validate' => '')) !!}
<div id="success">
<div class="col-sm-12">
#if(Session::has('success'))
<div class="alert alert-success" role="alert">
<strong> Success: </strong> {{ Session::get('success') }}
</div>
#endif
#if(count($errors) > 0)
<div class="alert alert-danger" role="alert">
<strong> Errors: </strong>
<ul>
#foreach($errors->all() as $error)
<li> {{ $error }} </li>
#endforeach
</ul>
</div>
#endif
</div>
</div>
{{ Form::text('name', null, array( 'placeholder' => 'Name...', 'class' => 'input', 'required' => '', 'minlength' => '10'))}}
{{ Form::email('email', null, array('placeholder' => 'Email Address...','class' => 'input', 'required' => '', 'type' => 'email'))}}
{{ Form::textarea('message', null, array('placeholder' => 'Message...', 'class' => '', 'required' => 'input', 'minlength' => '100')) }}
{{ Form::submit('Submit') }}
{!! Form::close() !!}
</div>
Route
Route::get('/', 'PagesController#getIndex') ->name('pages.index');
Route::post('/', 'PagesController#postIndex') ->name('index.post');
You are redirecting to the same route your form is posting. I assume that the route that render the view is a GET route and have another name, you should redirect to that route or the route that renders index.blade.php
This is why you have the with() method to chain the route() method on. So rather than use Session:flash(), you can simply add a with() method that flashes that message to the session for the next request:
return redirect()->route('pages.index')->with('success', 'Hello'. $name.', Your Form was successfully sent');
Or rather if your form was originally from the index page, then you simply don't have to remember the name of the route, simply use back() helper method, i.e:
return back()->with('success', 'Hello'. $name.', Your Form was successfully sent');

laravel 5.2 Restfull Api with admin panel stop working suddenly

I developed admin panel to add,edit,delete users in my website with Restfull Api. edit and delete work fine but add not.
when I add user it may work or this error may appear
The localhost page isn’t working
localhost is currently unable to handle this request.
This is my routes
Route::resource('admin/users','AdminUser');
This is store function in Admin user resource
public function store(Request $request)
{
//rules
$rules = array(
'name' => 'required',
'email' => 'required|email',
'password' => 'required|min:6|confirmed',
'password_confirmation' => 'required|min:6'
);
/*
validate the data user
**/
$validator = Validator::make($request->all(),$rules);
if ($validator->fails()) {
return view('admin.User.create_user')
->withErrors($validator)
->withInput(['page' => 'home']);
}
/*
Store the data user in the database
**/
$user = new User;
$user->name =$request->input('name');
$user->email = $request->input('email');
$user->password=bcrypt($request->input('password'));
$user->role='user';
$user->save(); //error here
//redirect
return redirect('admin/users')->with('message', 'Successfully added user!');
}
And this is create_user.blade.php
#extends('layouts.layout')
#section('content')
<section id="advertisement">
<div class="container">
<img src="{{asset('images/shop/advertisement.jpg')}}" alt="" />
</div>
</section>
<section>
<div class="container">
<div class="row">
<div class="col-sm-3">
<div class="left-sidebar">
#include('shared.sidebaradmin')
</div>
</div>
<div class="features_items"><!--features_items-->
<h2 class="title text-center">Add New Product</h2>
#if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
{{ Form::open(array('url' => 'admin/users')) }}
<div class="form-group">
{{ Form::label('name', 'Name') }}
{{ Form::text('name',null, array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('email', 'Email') }}
{{ Form::email('email',null, array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('password', 'Password') }}
{{ Form::password('password', array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('password_confirmation', 'Confirm Password') }}
{{ Form::password('password_confirmation', array('class' => 'form-control')) }}
</div>
{{ Form::submit('Add a new user !', array('class' => 'btn btn-primary')) }}
{{ Form::close() }}
</div><!--features_items-->
</div>
</div>
</section>
#endsection

Laravel 5.2 TokenMismatchException

I'd like to write a code in Laravel 5.2 which would upload photos, my problem is that once I start uploading many photos at once the site goes down.
It gives me this error: TokenMismatchException in VerifyCsrfToken.php line 67:
This error should appear only when the {{ csrf_field() }}, is missing from the form, but in this case it isn't, it's right there.
It works perfectly with less images. What could be the problem?
Controller
public function store(Request $request)
{
$rules = array(
'picturess' => 'mimes:jpeg,jpg,bmp,png',
);
$messages = array(
'mimes' => 'A feltöltetni kívánt kép nem felel meg a kritériumoknak. (Ilyen lehet a kép kiterjesztése: jpeg, jpg, bmp vagy png. A kép se lehet bármekkora.)',
'integer' => 'A beírt szőveg nem szám.',
'required' => 'Ennek a mezőnek a kitőltése kötelező.',
);
$validator = Validator::make(Input::all(), $rules, $messages);
if ($validator->fails()) {
$messages = $validator->messages();
return Redirect::back()->withInput()->withErrors($validator);
}
if (Input::hasFile('pictures')) {
$files = $request::file('pictures');
$file_count = count($files);
$uploadcount = 0;
$destinationPath = 'uploads';
$userId = Auth::user()->id;
foreach ($files as $file) {
if ($file->isValid()) {
$extension = $file->getClientOriginalExtension();
$pictureFileName = $this->makePictureFileName(0, $extension);
$thumbnailPictureFileName = $this->makePictureFileName(1, $extension);
Log::info('pictureFileName: '.$pictureFileName);
if ($file->move($destinationPath, $pictureFileName)) {
$uploadcount++;
$img = Image::make($destinationPath . '/' . $pictureFileName);
//$img = Image::make($file->getClientOriginalName());
$img->resize(277, null, function ($constraint) {
$constraint->aspectRatio();
});
$img->save($destinationPath . '/' . $thumbnailPictureFileName);
$picture = new Picture;
$picture->filename = $pictureFileName;
$picture->thumbnail_filename = $thumbnailPictureFileName;
$picture->user_id = $userId;
$picture->save();
}
} else {
Session::flash('picture-error', 'A feltöltetni kívánt kép nem megfelelő. (Valószínűleg túl nagy.)');
return redirect()->back()->withInput()->withErrors($validator);
}
}
if ($uploadcount == $file_count) {
Session::flash('success', 'A képek feltöltése sikeres.');
} else {
return redirect()->back()->withInput()->withErrors($validator);
}
}
//return Redirect::to('pictures/create');
return redirect()->back()->withInput()->withErrors($validator);
}
View
#extends('layouts.site')
#section('content')
<div class="row">
<div class="col-md-12">
{!! Form::open(array('method' =>'POST', 'url' => 'pictures', 'class' => 'uk-form', 'files'=> true)) !!}
{{ csrf_field() }}
<div class="form-group">
{!! Form::label('pictures', 'Kép', array('class' => '')) !!}
<div class="uk-form-controls">
{!! Form::file('pictures[]', array('class' => '','multiple'=>true)) !!}
</div>
</div>
<div class="form-group">
<button class="uk-button">Küldés</button>
</div>
#if ($errors->has('success'))
<div class="alert alert-danger" role="alert">
<p>{{ $errors->first('success') }}</p>
</div>
#endif
#if(Session::has('picture-error'))
<div class="alert alert-danger" role="alert">
<p class="errors">{!! Session::get('error') !!}</p>
</div>
#endif
#if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
{!! Form::close() !!}
</div>
</div>
#stop
Route
Route::group(['middleware' => ['web']], function () {
Route::get('/', 'SiteController#index');
Route::get('admin', 'AdminController#index');
Route::resource('pictures', 'PicturesController');
Route::resource('users', 'UsersController');
Route::auth();
});
{!! Form::open... will automatically add CSRF field protection, so you don't need this {{ csrf_field() }}.

displaying specific error messages in laravel 4.2

hello i have this form and i have validations for it. I have already finished doing the validations for in inside my controller and i can already display the error messages in my view but i wanted the error message to be beside the input area where it came from
here is my code in the view
{{ Form::open(array('url' => 'addParentAccnt')) }}
<div class="form-group">
{{ Form::label('username', 'Username') }}
{{ Form::text('username', Input::old('username'), array('class' => 'form-control','placeholder' => 'Insert username')) }}
</div>
<div class="form-group">
{{ Form::label('fName', 'First Name') }}
{{ Form::text('fName', Input::old('fName'), array('class' => 'form-control','placeholder' => 'Insert First Name')) }}
</div>
<div class="form-group">
{{ Form::label('lName', 'Last Name') }}
{{ Form::text('lName', Input::old('lName'), array('class' => 'form-control','placeholder' => 'Insert Last Name')) }}
</div> {{ Form::submit('Proceed to Next Step', array('class' => 'btn btn-primary')) }}
{{ Form::close()}}
in the bottom of my view i added this code to display the error messages
#if ($errors->any())
<ul>
{{ implode('', $errors->all('<p style="color:red" class="error">:message</p>')) }}
</ul>
#endif
the code inside my controller is this
$rules = array
(
'username' => 'required|min:10|max:50',
'fName' => 'required|alpha|min:1|max:80',
'lName' => 'required|alpha|min:1|max:80',
);
$validator = Validator::make(Input::all(), $rules, $messages);
if ($validator->fails())
{
return Redirect::to('createPa')
->withErrors($validator)
->withInput(Input::except('password'));
}
else
{
//do something
}
Change your view as following:
<div class="form-group">
{{ Form::label('username', 'Username') }}
{{ Form::text('username', Input::old('username'), array('class' => 'form-control','placeholder' => 'Insert username')) }}
{{ $errors->first('username', ':message') }}
</div>
<div class="form-group">
{{ Form::label('fName', 'First Name') }}
{{ Form::text('fName', Input::old('fName'), array('class' => 'form-control','placeholder' => 'Insert First Name')) }}
{{ $errors->first('fName', ':message') }}
</div>

Resources