SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Update_Profile' in 'field list' (SQL: update `users` set `updated_at` = 2021-01-11 00:01:39, - laravel

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Update_Profile' in 'field list' (SQL: update users set updated_at = 2021-01-11 00:01:39, Update_Profile = Update Profile where id = 12)
I am getting this error whenever a user tries to update his/her profile.
This is where the user click the UPDATE PROFILE
And this is the error I am getting
And I think the error is from here but I don't now
Can someone help me out please.

If update_profile is available in your table and you got that error probably this will be sloved with one of two ways below:
1 - Run command 'composer dumpautoload' in the terminal
2 - Clear this path contents : \storage\framework\views*

Related

Eloquent Intermediate Tabel with None Standard ID Column

While creating my database according to the eloquent standard, I ran into the problem that my table_name and id column name combined would be longer as 64 characters.
very_long_table_name.very_long_column_name_id
So I used a shorter column name as the foreign key in my Intermediate Table.
Migration file:
$table->unsignedBigInteger('short_id');
$table->foreign('short_id')->references('id')->on('very_long_table_name');
That worked fine, yet now I would like to insert a connection
Seeder.php:
$x->very_long_table_name()->attach($other_table_name->id);
I get the error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'very_long_column_name_id' in 'field list' (SQL: insert into very_long_table_name (just_an_id, very_long_column_name_id) values (1, 1))
What I would want is that it would use the column short_id instead of very_long_column_name_id to insert this, is there any cool way to fix this? or do I need to insert and query the connection manually if I keep the long names?
Like #Tim points out in the comments this needs to be done in the Model VeryLongTableName.php where you define the relationship:
public function very_long_table_name() {
return $this->belongsToMany(Model::class, 'very_long_table_name', 'local_id', 'short_id');
}

Laravel where in a relational database

I have two tables
Thread and Participants
Thread has many participants and I'm able to access it like so:
Thread::with('participants')->get();
The participants table has a column last_read
I would like to get all participants from thread WHERE last_read is NULL. I've tried this but it returns an error.
Thread::with('participants')
->where('last_read', NULL)
->get();
I am getting this error:
ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'last_read' in 'where clause' (SQL: select * from threads where last_read is null and threads.deleted_at is null)
Any idea how I can do this?
Since you want a query on relation table use whereHas
Thread::with('participants')
->whereHas('participants', function($q){
$q->where('last_read', NULL);
})->get();

sql 42S22 error in Laravel (choosing a column I didn't mention)

I am doing a basic project in Laravel, when trying to delete an entry, it generates this error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: select * from `employees` where `id` = 6 limit 1)
and it is true I don't have a column named 'id', instead I have employee_id, but why is it choosing id instead of employee_id?
Please explain from where did it bring this id column?
In your Employee model (Employee.php), add
protected $primaryKey = 'employee_id';
This will tell Laravel to use employee_id as the primary key for Empolyee objects.

Use JWT with uuid lumen

I am using jwt in luman and use primary key UUID hexadecimal.
And firstly i got issues to Authenticate token by passing in header the issue was -
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.id' in 'where clause' (SQL: select * from user` where users.id = 0 limit 1) "
but i solved it using " protected $primaryKey = 'uuid'; " put in model it fine.
But after i got another issue in 'jwt->attemp' it always give my UUID '30' in numeric number when i login but when i remove the code form model it's working fine. Please help me about this issues.
In your config/jwt.php change:
'identifier' => 'id'
To
'identifier' => 'uuid'

Laravel 5.2 exists validation cannot find column

I have wierd trouble during validating request in controller. I use exists validation rule. User is supposed to submit integer. This integer should exist as id in a single row of user_courses table. This row also should have column user_id equal to 158 - docs.
My validation rule:
'course_id' => 'integer|exists: user_courses, id, user_id, 158'
What I got instead:
PDOException in Connection.php line 333: SQLSTATE[42S22]: Column not
found: 1054 Unknown column ' id' in 'where clause'
My Table:
id, user_id, created_at, updated_at
Problem was in the spaces:
'course_id' => 'integer|exists: user_courses, id, user_id, 158' // incorrect
'course_id' => 'integer|exists:user_courses,id,user_id,158' // correct
Original code would confuse laravel to search for column names like this:
' user_courses'

Resources