Reputation: 561
So i came across a bug in my application. When i want to update an project everything updates smoothly. Except one input. the projectnaam
won't change. In the flashdata I send after success shows the changed projectnaam but after i check the database everything is changed except projectnaam
My code :
public function updateProject(Request $request){
$input = $request->input('projectnaam');
$data = array(
'titel' => $request['titel'],
'status' => $request['status'],
'prioriteit' => $request['prioriteit'],
'soort' => $request['soort'],
'projectnaam' => $request['projectnaam'],
'projecturl' => $request['projecturl'],
'gebruikersnaam' => $request['gebruikersnaam'],
'wachtwoord' => bcrypt($request['wachtwoord']),
'omschrijvingproject' => $request['omschrijvingproject'],
);
Project::where('projectnaam', '=', $input)->update($data);
$request->session()->flash('alert-success', 'Project '. $request['projectnaam']. ' veranderd.');
return redirect('/projectmuteren');
}
I hope anyone of you sees my mistake :P
Upvotes: 0
Views: 2180
Reputation: 15941
You are not updating projectnaam
in your code because there is nothing to update. I'll take out 3 lines of code from your example for brevity's sake.
$input = $request->input('projectnaam');
'projectnaam' => $request['projectnaam'],
Project::where('projectnaam', '=', $input)->update($data);
$request->input('projectnaam');
is the same thing as $request['projectnaam']
. Therefore, $input
is also equal to $request['projectnaam']
.
In other words, you are looking for the Project based on the provided projectnaam
value. Then you are "updating" it with that exact same value so there is nothing to update. The two are one and the same.
To put things more concretely, lets assign it a value of 1. You are searching for Project where projectnaam
is equal to 1 and then "updating" it with the value of 1 so naturally, there is nothing to update.
Upvotes: 1
Reputation: 15549
You didn't include 'projectnaam'
in your $fillable
array in class Project
Upvotes: 1