Ive been trying to check the fields that a user submitted from the form with the database fields to see if there was any change made if it was let the save() query run, else send a message that no changes made
public function update(Request $request,$id)
{
$this->validate($request, [
'title' =>'required',
'notes' =>'required',
'description' =>'required'
]);
$editinc = Editted::find($id);
if($editinc > 0) {
dd($editinc);
}
$data = $request->all();
$post= Joborder::find($id);
//before this query runs i want to check my fields with db
//if no changes has been this should not be executes
$post->fill($request->input())->save();
return redirect('/thehood')->with('success','WE DID IT.');
}
Additional Info : im a newbie in Laravel so take it easy on me.
if isDirty() is possible , how ? I checked lots of questions still have no clue how to use it.
if its not possible then is there a Laravel way? something that checks and if there are difference it will ONLY change their value NOT perform a full update on every field.
Edited : this could be a way but I'm pretty sure there is Laravel way that I just don't know about it??!
$post= Joborder::find($id);
$data = $request->all();
foreach($data as $dat => $val) {
if($dat=="_token" || $dat=="_method") continue;
if($data[$dat] == $post->$dat) {
continue;
}else{
$post->$dat = $data[$dat];
$post->save();
$flag=1;
}
}
if($flag == 0 ) {
return redirect('/thehood')->with('success','NO EDIT HAS BEEN DoNE.');
}else{
return redirect('/thehood')->with('success','one or more Field has been edited .');
}
Here is what you can do, please enter all the fields you want to compare in the query as I am not entering all of them.
$exist = Joborder::where('title', $request->input('title'))->where('notes', $request->input('notes'))->first();
if($exist)
{
//Insert into database.
}