i have this ruote.
Route::get('/artist/{id}/{slug}', 'HomeController#artist')->name('artist');
and this is the moded artist.
public function artist($id,$slug){
$artist = Artist::where('id', $id)->where('slug', $slug)->first();
$hits = Artist::where('id', $id)->where('slug', $slug)->increment('week_hits');
return view('front.artist', compact('artist'));
}
whati want is increment week_hits field in my artists table. whenever a specific artist page is visited by the user.
but iam getting this error.
QueryException in Connection.php line 647:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'week_hits' in 'field list' (SQL: update `artists` set `week_hits` = `week_hits` + 1, `updated_at` = 2017-02-26 16:20:04 where `id` = 1 and `slug` = xasan-aadan-samatar)
Related
I want to update my database with Laravel eloquent update, but response is always 500
This is my model
class Tunggakan extends Model
{
protected $table = 'kredit_tunggakan';
/**
* #var array
*/
}
This is the function
public function statusTunggakan(){
$status = Tunggakan::find(2);
$status -> id_status = 77;
$status -> save();
}
This is the route
Route::prefix('tunggakan')->group(function () {
Route::post('/statusTunggakan','TunggakanControl#statusTunggakan');
});
Exception:
[2022-03-24 11:20:14] production.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'kredit_tunggakan.updated_at' in 'field list' (SQL: update kredit_tunggakan set id_status = 77, kredit_tunggakan.updated_at = 2022-03-24 11:20:14 where id = 2) {"exception":"[object] (Illuminate\\Database\\QueryException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'kredit_tunggakan.updated_at' in 'field list' (SQL: update kredit_tunggakan set id_status = 77, kredit_tunggakan.updated_at = 2022-03-24 11:20:14 where id = 2)
Thanks before, for helping..
Loking at the exception:
Column not found: 1054 Unknown column 'kredit_tunggakan.updated_at
Seems like you don't have updated_at column in your database table. There are two solutions for this:
I: Create/update your migration to include timestamp fields:
$table->timestamps();
II: Set timestamps to false when updating the record:
$status = Tunggakan::find(2);
$status->timestamps = false;
$status -> id_status = 77;
$status -> save();
I have a laravel application in xampp with php 7, when I want to login I get an error 500, if I check the error_log in the storage folder, I see that it is the following error:
[2021-04-16 23:36:32] live.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'username' in 'where clause' (SQL: select * from `users` where `username` = admin and `users`.`deleted_at` is null limit 1)
{"exception":"[object] (Illuminate\\Database\\QueryException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'username' in 'where clause' (SQL: select * from `users` where `username` = admin and `users`.`deleted_at` is null limit 1) at
C:\\xampp\\htdocs\\p2\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php:664, PDOException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'username' in 'where clause' at C:\\xampp\\htdocs\\p2\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php:326)
This is my first time whit laravel, I don't know how to resolve this issue, the code of the lines 326 and 664 are the next:
326
public function select($query, $bindings = [], $useReadPdo = true)
{
return $this->run($query, $bindings, function ($query, $bindings) use ($useReadPdo) {
if ($this->pretending()) {
return [];
}
// For select statements, we'll simply execute the query and return an array
// of the database result set. Each element in the array will be a single
// row from the database table, and will either be an array or objects.
$statement = $this->prepared($this->getPdoForSelect($useReadPdo)
->prepare($query));
$this->bindValues($statement, $this->prepareBindings($bindings));
$statement->execute();
return $statement->fetchAll();
});
}
Is only the catch of teh error, maybe could be usefull
protected function runQueryCallback($query, $bindings, Closure $callback)
{
try {
$result = $callback($query, $bindings);
}
// If an exception occurs when attempting to run a query, we'll format the error
// message to include the bindings with SQL, which will make this exception a
// lot more helpful to the developer instead of just the database's errors.
catch (Exception $e) {
throw new QueryException(
$query, $this->prepareBindings($bindings), $e
);
}
I received this application from a company that has me as an intern, but they didn't give me any more help or guidance, they just want it to work.
I appreciate any comments that can help me solve it.
public function increment($id)
{
$this->model->where("id",'=', $id)->update(['rating'=> DB::raw('count+1')]);
}
I am getting the following error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'count' in
'field list' (SQL: update news set rating = count+1, updated_at
= 2019-04-13 08:12:51 where id = 5)
I also tried
->update(['rating'=>'count+1']);
You are not telling the query builder on which table you are performing the query, so DB::raw('count+1') makes no sense.
You can try to use the eloquent increment method like this:
$this->model->where("id", $id)->increment('rating');
Thanks #Tharaka removed the extra call to save().
I'm getting this error when I'm trying to assign a value to all the columns in a table.
Controller
public function updateallcompany(Request $request, $id)
{
$active = $request->input('active');
AccessCode::where('company_id', $id)->update([$active, 'active']);
return view('pages.accesscode.showallaccesscodecompany')
->with('success', "AccessCodes Updated");
}
Error
SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field
list' (SQL: update access_codes set 0 = Yes, 1 = active, updated_at = 2019-04-11 11:10:03 where company_id = 2)
You must pass the $active value to the field active.
You can see Mass Updates example on laravel documentation:
https://laravel.com/docs/5.8/eloquent
Try:
AccessCode::where('company_id', $id)->update(['active' => $active]);
Not delete record from database in cakephp
my query for delete record.
public function del_mail($mailid)
{
$this->Mymail->deleteAll(array('mailid'=>$mailid));
$this->Session->setFlash(__('Delete Successful', true), 'default');
$this->redirect($this->referer());
}
Error.
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Mymail.id' in 'field list'
SQL Query: SELECT DISTINCT `Mymail`.`id` FROM `babysoft_storel`.`mymails` AS `Mymail` WHERE `mailid` = 1
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Mymail.id' in 'field list'
You have an error of mysql query and are you sure you have the 'Mymail.id' in your table field?
According to your comment below Please try this :
public function del_mail($mailid)
{
$this->Mymail->deleteAll(array('Model.mailid'=>$mailid)); //where Model is your Model you used to retrieving the mailid field.
$this->Session->setFlash(__('Delete Successful', true), 'default');
$this->redirect($this->referer());
}