I m try to insert data to db ! but function is working ok, it redirect to route assigned ! no error! but data is not getting added in db! I am not able to figure out ! anyhelp?
public function addfav($webmasterId,$id)
{
// Check Permissions
$data_sections_arr = explode(",", Auth::user()->permissionsGroup->data_sections);
if (Auth::user()->id =='1') {
return Redirect::to(route('NoPermission'))->send();
}
$dlt=DB::table('favads')->insertGetId([
['user_id' => Auth::user()->id, 'topic_id' => $id]
]);
//
// General for all pages
$GeneralWebmasterSections = WebmasterSection::where('status', '=', '1')->orderby('row_no', 'asc')->get();
// General END
//Webmaster Topic Details
$WebmasterSection = WebmasterSection::find($webmasterId);
if (!empty($WebmasterSection)) {
return redirect()->route('fav',['webmasterId'=>$webmasterId]);
} else {
return redirect()->route('NotFound');
}
}
Why are you having two [] ? Remove one of them, I think this is the problem
Change
$dlt=DB::table('favads')->insertGetId([
['user_id' => Auth::user()->id, 'topic_id' => $id]
]);
To
$dlt=DB::table('favads')->insertGetId(
['user_id' => Auth::user()->id, 'topic_id' => $id]
);
Check with try and catch, what error are you receiving
try{
$dlt=DB::table('favads')->insertGetId(
['user_id' => Auth::user()->id, 'topic_id' => $id]
);
dd($dlt);
}catch(\Exception $e){
dd($e->getMessage());
}
You have to use like this
$dlt = new Favad();
$dlt->user_id = Auth::user()->id;
$dlt->topic_id = $id;
$dlt->save();
Be sure that you are using the following code use App\Favad; in your controller.
You should insert data the following way:
$dlt = new Favad;
$dlt->user_id = Auth::user()->id;
$dlt->topic_id = $id;
$dlt->save();