Method validateConfirm does not exist (Laravel) - php

I am following Dayle Rees' Laravel tutorial, trying to build a simple registration page.
If I submit the registration form with validation errors, the page reloads and shows me the validation errors. However, when I key in correct values and submit, I get the following error -
BadMethodCallException
Method [validateConfirm] does not exist.
This is my register.blade.php -
<!doctype html>
<html lang="en">
<head>
</head>
<body>
<h1>Registration form</h1>
{{ Form::open(array('url' => '/registration')) }}
{{-- Username field. ------------------------}}
{{ Form::label('username', 'Username') }}
{{ Form::text('username') }}
{{ $errors->first('username', '<span class="error">:message</span>') }}
<br/>
{{-- Email address field. -------------------}}
{{ Form::label('email', 'Email address') }}
{{ Form::email('email') }}
{{ $errors->first('email', '<span class="error">:message</span>') }}
<br/>
{{-- Password field. ------------------------}}
{{ Form::label('password', 'Password') }}
{{ Form::password('password') }}
{{ $errors->first('password', '<span class="error">:message</span>') }}
<br/>
{{-- Password confirmation field. -----------}}
{{ Form::label('password_confirmation', 'Password confirmation') }}
{{ Form::password('password_confirmation') }}
<br/>
{{-- Form submit button. --------------------}}
{{ Form::submit('Register') }}
{{ Form::close() }}
</body>
</html>
And this is my routes.php [NOTE : The issue goes away if I remove the rule for password]
Route::get('/', function()
{
return View::make('register');
});
Route::post('/registration', function()
{
// Fetch all request data.
$data = Input::all();
// Build the validation constraint set.
$rules = array(
'username' => 'required|min:3|max:32',
'email' => 'required|email',
'password' => 'required|confirm|min:3'
);
// Create a new validator instance.
$validator = Validator::make($data, $rules);
if ($validator->passes()) {
// Normally we would do something with the data.
return 'Data was saved.';
}
return Redirect::to('/')->withErrors($validator);
});

Issue seems to be due to using confirm instead of confirmed. Resolved!

you can include ->back() or use
must be changed in your code , its required
return Redirect::to('/')
->back()
->withErrors($validator);

Related

How to submit a form using PUT http verb in Laravel

I know that this question may have been made but I just can't get it to work. if someone could help me I would be very grateful. I have colletive/form installed but the answer can be an html form tag too.
Now listing my form, my route and my exception.
{{ Form::model( array('route' => array('casas.update', 238), 'method' => 'PUT')) }}
<input type="hidden" name="_method" value="PUT">
-
Route::resource('casas', 'CasasController');
exception:
MethodNotAllowedHttpException in RouteCollection.php line 218:
With plain html / blade
<form action="{{ route('casas.update', $casa->id) }}" method="post">
{{ csrf_field() }}
{{ method_field('put') }}
{{-- Your form fields go here --}}
<input type="submit" value="Update">
</form>
Wirth Laravel Collective it may look like
{{ Form::model($casa, ['route' => ['casas.update', $casa->id], 'method' => 'put']) }}
{{-- Your form fields go here --}}
{{ Form::submit('Update') }}
{{ Form::close() }}
In both cases it's assumed that you pass a model instance $casa into your blade template
In your controller
class CasasController extends Controller
{
public function edit(Casa $casa) // type hint your Model
{
return view('casas.edit')
->with('casa', $casa);
}
public function update(Request $request, Casa $casa) // type hint your Model
{
dd($casa, $request->all());
}
}

delete function Laravel 5.2

I've been learning laravel 5.2 recently, and i've made a delete function which should delete records from my database but instead of deleteing the records it's adding a blank row into my database
This is the Route im using:
Route::resource('producten', 'ProductenController', ['only' => ['index', 'store', 'destroy', 'edit', 'update', 'create']]);
This is the controller function i use for it
public function destroy(request $request , product $product)
{
$product->delete();
return redirect(Route('producten.index'));
}
This is the form i've made for it.
{{ Form::Open(['Route' => 'producten.destroy', $product], ['method' => 'delete']) }}
{{ Form::Submit('delete')}}
{{ Form::close() }}
when i viewed the source-code it said it was using a POST method instead of a delete method, and also when i add($product) i got a blank page, also i found out that when i hit the submit button it goes to the store method i've made and i dont know why,
if u need more information just let me know and i'll add it in the question
route and method should be in the same array, not in two differents arrays.
{{ Form::Open(['method' => 'DELETE', 'route' => ['producten.destroy', $product]]) }}
{{ method_field('DELETE') }}
{{ Form::Submit('delete')}}
{{ Form::close() }}
I think you have something wrong with form. Can you try with this:
<form action="{{ route('producten.destroy', ['product' => $product->id]) }}" method="POST">
{{ csrf_field() }}
{{ method_field('DELETE') }}
<button type="submit">Remove</button>
</form>

Laravel auth not working using correct username/password combination

For some reason, I'm unable to login with the correct username/password combination. I'm using flash messages to show when the login information is incorrect.
I've tried creating multiple accounts to make sure I wasn't actually entering the wrong login credentials, but after about an hour of fiddling it's still not working.
Any help would be greatly appreciated! Thank you!
Here's what I got.
UsersController.php (postCreate) - Function that creates my user account (working perfectly fine)
public function postCreate() {
$rules = array(
'username'=>'required|unique:users,username|alpha_dash|min:4',
'password'=>'required|min:8|confirmed',
'password_confirmation'=>'required|min:8',
'email'=>'required|email|unique:users,email'
);
$input = Input::only(
'username',
'password',
'password_confirmation',
'email'
);
$validator = Validator::make($input, $rules);
if($validator->fails())
{
return Redirect::to('register')->withErrors($validator)->withInput();
}
//$confirmation_code = str_random(30);
User::create(array(
'username'=>Input::get('username'),
'password'=>Hash::make(Input::get('password')),
'email'=>Input::get('email')
//'comfirmation_code' => $confirmation_code
));
// Mail::send('email.verify', function($message) {
// $message->to(Input::get('email'), Input::get('username'))
// ->subject('Verify your email address');
// });
// Flash::message('Thanks for signing up! Please check your email.');
return Redirect::to('login')->with('message', 'Thanks for signing up! Please check your email.');
}
UsersController.php (postLogin) - Function that logs me into account
public function postLogin() {
$user = array(
'email'=>Input::get('email'),
'password'=>Input::get('password')
);
if (Auth::attempt($user)){
return Redirect::intended('account')->with('message', 'Welcome back!');
} else {
return Redirect::to('login')
->with('message', 'Your username/password was incorrect')
->withInput();
}
}
Routes.php
Route::get('login', array('as'=>'login', 'uses'=>'UsersController#getLogin'));
Route::post('login', array('before'=>'csrf', 'uses'=>'UsersController#postLogin'));
login.blade.php - My login Page
#if($errors->has())
<p>The following errors have occured:</p>
<ul id="form-errors">
{{ $errors->first('username', '<li>:message</li>') }}
{{ $errors->first('password', '<li>:message</li>') }}
</ul>
#endif
#if (Session::has('message'))
<p>{{ Session::get('message') }}</p>
#endif
{{ Form::open(array('action'=>'login')) }}
<p>
{{ Form::label('username', 'Username') }}<br />
{{ Form::text('username', Input::old('username')) }}
</p>
<p>
{{ Form::label('password', 'Password') }}<br />
{{ Form::password('password') }}
</p>
<p>
{{ Form::submit('Login') }}
</p>
{{ Form::close() }}
In your
UsersController.php (postCreate) - : You are able to create using password with Hash 'password'=>Hash::make(Input::get('password')),
AND
UsersController.php (postLogin) : You are trying to login using 'password'=>Input::get('password') So this should replace with
'password'=>Hash::make(Input::get('password'))
Also hashed passwords required 64 charactters for database field. so check that too.
I found the issue to be with the amount of characters I was allowing to be entered into the password field of the database.
I had the password column set to: $table->string('password', 32); varchar(32) which wont work because hashed passwords in laravel require at least 64 characters.
Changing the password column in my database to varchar(64) fixed the issue.

Laravel Eloquent Model - can't access database

I'm trying to write a simple site that can write and read of a simple mysql database, using Laravel, but I've run into a full stop as Laravel doesn't seem to be recognising my model. Either that or I am doing something wrong.
My model:
class Submission extends Eloquent
{
public static $timestamps = true;
protected $fillable = array('location', 'twitter', 'instagram', 'website');
}
My form:
#extends('layout')
#section('content')
{{ Input::old('twitter') }} <br />
{{ Input::old('instagram') }} <br />
{{ Input::old('website') }} <br />
{{ Form::open(array('url' => '/submission', 'files' => true)) }}
<div class="form-group">
{{ Form::label('twitter', 'Twitter') }}
{{ Form::text('twitter', '', array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('instagram', 'Instagram') }}
{{ Form::text('instagram', '', array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('website', 'Website') }}
{{ Form::text('website', '', array('class' => 'form-control')) }}
</div>
{{ Form::button('Submit image', array('class' => 'btn btn-success', 'type' => 'submit')) }}
<input type="hidden" name="post" value="yes">
{{ Form::close() }}
#stop
My controller:
public function postView()
{
$submission = new Submission;
$submission->twitter = Input::get('twitter');
$submission->instagram = Input::get('instagram');
$submission->website = Input::get('website');
$submission->save();
return Redirect::to('submission')->withInput();
}
My database looks like: id location twitter instagram website created_at updated_at
I know that my database config is correct as I can retrieve information using DB::table('submissions')->get(); so from what I can tell it's Laravel that's not recognising my model?
EDIT:
Turns out that changing public static $timestamps = true; to public $timestamps = true; fixed it.
Does this works :
DB::table('submissions')->get();
as it should return everything in the table. If it works then Eloquent can't find your table you can try to put that in your model:
protected $table = 'submissions';
It will define explicitly the table name in the model, even if it seems correct in your case
Otherwise you need to tell what exactly laravel answers when you made a request.
Do you have an error message in your browser ?
Do you have an error message in your log file (check the app/storage/logs folder)
Is your database configuration ok ? (app/config/database.php)
Did you create the table using a laravel migration ?
Hope it helps

Laravel 4 getting information from database for drop-down form

I am trying to make a simple authentication application and I have the login/signup form in place and it is working correctly. However, I am having issues with populating the drop-down field for a zip-code from another table. I am not really sure how i should approach this. Most of the time i would just use straight mysql query but I am assuming there is an easier way.
Controller: (would love for the zip_code table to go here.)
public function getSignUp() {
$userdata = array(
'email' => Input::get('email'),
'password' => Hash::make(Input::get('password'))
);
$user = new User($userdata);
$user->save();
return Redirect::to('dashboard');
}
Route
Route::post('signup', 'LoginController#getSignUp');
signup.blade.php
{{ Form::label('email', 'Email:') }}<br />
{{ Form::text('email') }}<br />
{{ Form::label('password', 'Password:') }}<br />
{{ Form::password('password') }}<br />
{{ Form::label('zip_code', 'Zip Code:') }}<br />
{{ Form::select('zip_code', array('zip_code' => '', 'city' => '')); }}<br />
{{ Form::submit() }}<br />
{{ Form::close() }}
This is how I would normally call database information before this
public function showHome()
{
$testimonials = DB::select('SELECT * FROM `testimonials` WHERE `id`=' . mt_rand(1, 2));
return View::make('home.index', array('pageTitle' => 'Home'))->with('testimonials', $testimonials);
}
but with me not returning a view and therefor no variables are going to be passed I am not sure how to achieve this
Any advice would be highly appreciated!
You can easily list out data from an Eloquent model for a select field using the lists() function.
Testimonial::lists('content', 'id');

Categories