Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
Data not getting inserted to db - laravel

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');
        }
    }
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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());
}
over 4 years ago · Santiago Trujillo Report

0

You have to use like this

$dlt = new Favad();
$dlt->user_id =  Auth::user()->id;
$dlt->topic_id = $id;
$dlt->save();
over 4 years ago · Santiago Trujillo Report

0

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();
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!