Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

editable field, update with primary key other than id #278

Closed
stef740 opened this issue Sep 9, 2021 · 0 comments · Fixed by #282
Closed

editable field, update with primary key other than id #278

stef740 opened this issue Sep 9, 2021 · 0 comments · Fixed by #282

Comments

@stef740
Copy link

stef740 commented Sep 9, 2021

Hello, great package !

For editable fields, nice to have option to have non standard primary key when updated.

I have overridden your LivewireDatatables\Traits\WithCallbacks :

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;

trait WithCallbacks
{
    public function edited($value, $table, $column, $rowId )
    {
	$primaryKey = app("App\\Models\\" . Str::studly(Str::singular($table)))->getKeyName();

        DB::table($table)
            ->where($primaryKey, $rowId)
            ->update([$column => $value]);

        $this->emit('fieldEdited', $rowId);
    }
		
}

Do you have a better solution ?
Thks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant