Support the ongoing development of Laravel.io →
Database Eloquent

I am struggling to fix the following SQL error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column '1' in 'where clause' (SQL: select count(*) as aggregate from users where 1 = GoodBytesUK)

I have a form to update the users profile, which is submitted to profile.update

{{ Form::model($user->profile, ['method' => 'PATCH', 'route' => ['profile.update', $user->username]]) }}
...

my update function

	public function update($username)
	{
		$user = $this->getUserByUsername($username); // grabs the username (probably where the error is coming from)

		$input = Input::only('username', 'email', 'location', 'twitter_username', 'soundcloud_username');

		$rules = [
			'username' => 'required|unique:users,'.$user['id'],
			'email' => 'required|email|unique:users,'.$user['id'],
			'password' => 'sometimes|required|confirmed,'.$user['id']
		]; // appending user id so that it will ignore the required rule
		
		$validator = Validator::make($input, $rules);

		if ($validator->fails())
		{
    	echo $validator->messages();
		}
		else
		{
			$user->save();
			return Redirect::route('registration.edit', $user->username); // save the update and redirect
		}

getUserByUsername is:

	public function getUserByUsername($username)
	{
		return User::whereUsername($username)->firstOrFail();
	}

Any ideas? i can't seem to get passed it.

It looks like the number 1, which is the actual user id, is being picked up as the column name, which should be user_id

Last updated 3 years ago.
0

bump:)

Last updated 3 years ago.
0

Is this working ?

public function getUserByUsername($username)
{
    return User::where('username', '=', $username)->firstOrFail();
}
Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.