Home > Blockchain >  Insert value in existing key name in laravel
Insert value in existing key name in laravel

Time:12-08

public function store($request)
    {
        return DB::table('website_setup')->select('header_logo')->insertGetId([
            'value' => $request->header_logo   
        ] 
        );   
    }

table

 Schema::create('website_setup', function (Blueprint $table) {
                $table->id();
                $table->string('key');
                $table->longText('value')->nullable();
                $table->timestamps();
            });

And some keys are already created in database table

CodePudding user response:

You can use the upsert() method to insert new records and to update existing records with new values that you specify.

public function store($request)
{
        return DB::table('website_setup')->upsert([
            'value' => $request->header_logo   
        ]);   
}

Or use update(). Similar to the insert method, the update method accepts an array of columns and values that indicate the columns to be updated.

public function store($request, $id)
{
    return DB::table('website_setup')
              ->where('id', $id)
              ->update([
                'value' => $request->header_logo   
              ]);   
}
  • Related