jeudi 27 juin 2019

Error in Updating data, caused by unknown column in Laravel REST API

I already finished the create and read in my laravel rest api project.

But when I tried to test the "PUT" method for updating it shown me an error. The error itself i dont know how to resolve that bcs I am still new to laravel. My table name is "tb_peminjaman", but the update method read it as a column of its table. Anyway, I didn't create the tables using migration cause I have my own table created directly using phpmyadmin, so basically the migration filled with default value.

Here is the Screenshot of my Error shown by Postman>

"I've tried to change my code also disable the timestamps because it could be caused any error for my project. Here I show you my Update code in controller."

public function updatePinjam(Request $request, $id){
        if(Pinjam::where('no_pengajuan',$id)->exists()){
            $pinjam = Pinjam::find($id);
            $pinjam->ketua_kegiatan = is_null($request->ketua_kegiatan) ? $pinjam->ketua_kegiatan : $request->ketua_kegiatan;
            $pinjam->lab = is_null($request->lab) ? $pinjam->lab : $request->lab;
            $pinjam->level = is_null($request->level) ? $pinjam->level : $request->level;
            $pinjam->tanggal_mulai = is_null($request->tanggal_mulai) ? $pinjam->tanggal_mulai : $request->tanggal_mulai;
            $pinjam->tanggal_selesai = is_null($request->tanggal_selesai) ? $pinjam->tanggal_selesai : $request->tanggal_selesai;
            $pinjam->jam_mulai = is_null($request->jam_mulai) ? $pinjam->jam_mulai : $request->jam_mulai;
            $pinjam->jam_selesai = is_null($request->jam_selesai) ? $pinjam->jam_selesai : $request->jam_selesai;
            $pinjam->daftar_nama = is_null($request->daftar_nama) ? $pinjam->daftar_nama : $request->daftar_nama;
            $pinjam->keperluan = is_null($request->keperluan) ? $pinjam->keperluan : $request->keperluan;
            $pinjam->kontak_ketua = is_null($request->kontak_ketua) ? $pinjam->kontak_ketua : $request->kontak_ketua;
            $pinjam->app_laboran = is_null($request->app_laboran) ? $pinjam->app_laboran : $request->app_laboran;
            $pinjam->app_kalab = is_null($request->app_kalab) ? $pinjam->app_kalab : $request->app_kalab;
            $pinjam->app_kajur = is_null($request->app_kajur) ? $pinjam->app_kajur : $request->app_kajur;
            $pinjam->app_pudir = is_null($request->app_pudir) ? $pinjam->app_pudir : $request->app_pudir;
            $pinjam->save();
            return response()->json([
            "message" => "Perubahan Berhasil DiLakukan!"
        ], 200);
        } else {
        return response()->json([
            "message" => "Pinjam not found"
        ], 404);
    }
    }

And here is the ERROR MESSAGE:

Illuminate\Database\QueryException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'tb_peminjaman.id' in 'where clause' (SQL: select * from `tb_peminjaman` where `tb_peminjaman`.`id` = 15 limit 1) in file C:\xampp\htdocs\coba_api_laravel\vendor\laravel\framework\src\Illuminate\Database\Connection.php on line 664

Please kindly help me to solve this Error, cause this is an important thing for me to continue to finish my project soon. Thank you so much



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire