i need to compare Database Values with the inputs from Form this a a part of my code
public function update($id, Request $request) { $requestData = $request->all(); $website_info = WebsiteInfos::findOrFail($id); if ( $website_info->all() == $request->all()) { Session::flash('alert-info', 'No Change have been made'); return redirect('admin/website_infos'); } else { $website_info->update($requestData); Session::flash('alert-success', 'WebsiteInfos updated!'); return redirect('admin/website_infos'); } }
i need to compare $request->all() with db value ! i try this ! the if is ignored and always Show me the Success alert
Advertisement
Answer
The simplest way to do this is to find the record in a query.
$website_info = WebsiteInfos::where([ ['id', '=' ,$id], ['name', '=', $request->name], ['email', '=', $reqest->email] ])->first(); if ($website_info != null) { Session::flash('alert-info', 'No Change have been made'); return redirect('admin/website_infos'); } else { $website_info->update($requestData); Session::flash('alert-info', 'No Change have been made'); return redirect('admin/website_infos'); }