#Couldn't delete or update data for User table (default created by laravel)

35 messages · Page 1 of 1 (latest)

lusty moon
#

I don't know when and why this is happen. But, before I make a lot of changes in different part of feature.
The deleted button of administrator feature is working fine.

I use resource to be my route path:
Route::resource('administrator', AdministratorController::class)->except('create', 'show', 'edit');

If anyone here, ever had the same issue. I need your help guys

mortal dome
#

What does the button link to?

lusty moon
#
<form action="{{ route('administrator.destroy', $model->id) }}" method="POST">
                @csrf @method('DELETE')
                <button type="submit" class="btn btn-sm btn-danger rounded-3 delete-dialog">
                    <i class="bi bi-trash3"></i>
                </button>
            </form>

I don't even update the changes to the data, but i can store new data

#

this happen just in User table that created by default in laravel

#

In other table that i've create my own. it's working fine

#

Am I miss something in User model?
I already put protected $fillable = [ 'email',
'name',
'password',
'position',
'last_login', ] tho

#

Couldn't delete or update data for Route::resource()

#

Couldn't delete or update data for User table (default created by laravel)

finite orbit
#

show your destroy function, and also share error in flare

lusty moon
#

destroy function:

public function destroy(User $user): RedirectResponse
    {
        $user->delete();
        return redirect()->route('administrator.index')->with('success', 'Data berhasil dihapus!');
    }
lusty moon
#

the success response appear, but nothing has change

finite orbit
lusty moon
finite orbit
lusty moon
#

waitt

#

Here what's coming up

finite orbit
#

The problem is you use route resource (administrator) but you try to bind with User model. Try like this

public function destroy($id): RedirectResponse
{
    User::find($id)->delete();
    return redirect()->route('administrator.index')->with('success', 'Data berhasil dihapus!');
}
lusty moon
#

Alright, let me try

lusty moon
finite orbit
lusty moon
#

user id

finite orbit
lusty moon
#

wait

#

That's work 🤣

#

But why?

finite orbit
#

The problem is you use route resource (administrator) but you try to bind with User model

#

If you use route resource as 'users' then it will work

lusty moon
#

I see, thank you so much bro

finite orbit
#

wc bro

lusty moon
finite orbit
#

just change the url eg: from 'administrator' to 'users' but this may have some impact since you need to considers all the others routes (index, store etc)

lusty moon
#

Oke

static pine