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

Error when update mahasiswa #1

Open
Uniclowns opened this issue Apr 28, 2024 · 1 comment
Open

Error when update mahasiswa #1

Uniclowns opened this issue Apr 28, 2024 · 1 comment

Comments

@Uniclowns
Copy link
Owner

i use protected $primaryKey = 'NIM';
public $incrementing = false;
protected $keyType = 'string';
(IN Mahasiswa Model)

it's already fine when store/add data to database but when i want to update the data, it's alwasys error.

@fasaya
Copy link

fasaya commented May 3, 2024

On the controller you received model as a parameter Mahasiswa $mahasiswa which by default will look for the data by id (which you don't have) that is why you're getting Unknown column id error.

On resources/views/mahasiswa/edit.blade.php you pass $mahasiswa->NIM, so you could change your update method on your controller as:

    public function update(Request $request, $mahasiswa) : RedirectResponse
    {
        $mahasiswa = Mahasiswa::where('NIM', $mahasiswa)->findOrFail();

        $firstData = [
            'NIM' => 'required|string|max:16|unique:mahasiswas,NIM,' . $mahasiswa->NIM,
            'nama' => 'required|string|max:250',
            'jurusan' => 'required|string|max:255',
            'prodi' => 'required|string|max:255',
            'alamat' => 'required|string|max:255',
            'ttl' => 'required|string|max:255',
            'no_hp' => 'required|string|max:255',
        ];

        $validated = $request->validate($firstData);

        $mahasiswa->update($request->all());
        return redirect()->route('mahasiswas.index')->withSuccess('Data Mahasiswa is updated successfully');
    }

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

No branches or pull requests

2 participants