skip to Main Content

insert into ibuhamils (id_ibu, berat_badan, tinggi_badan, lila, t_darah, keluhan, tgl_periksa, updated_at, created_at) values (?, 54, 159, 20, 120/80, Tidak Ada, 2023-08-25, 2023-08-25 11:57:40, 2023-08-25 11:57:40)

help me solve this problem!!!

my controller

public function store(Request $request){
        
         // menerima data request
         $ibuhamil = [
            'id_ibu' =>$request->id_ibu,
            'berat_badan' => $request->berat_badan,
            'tinggi_badan' => $request->tinggi_badan,
            'lila' => $request->lila,
            't_darah' => $request->t_darah,
            'keluhan' => $request->keluhan,
            'tgl_periksa' => $request->tgl_periksa,
        ];

         Ibuhamil::create($ibuhamil);

         Alert::success('Data Berhasil Ditambah');
 
         return redirect()->route('ibuhamil')->with([
             'success' => 'Data Berhasil Di Tambah'
         ]);
    } 

My Views

  <form action="{{ route('admin.ibuhamil.store')  }}" method="POST">
    @csrf
    <div class="row">
        <div class="col-12">
            <div class="card shadow mb-4">
                <div class="card-header py-3">
                    <h6 class="m-0 font-weight-bold text-primary">{{ isset($ibuhamil) ? 'Form Edit Data Ibu Hamil':'Form Tambah Data Ibu Hamil' }}</h6>
                </div>
                <div class="card-body">
                    <div class="form-group">
                        <label for="id_ibu" style="font-weight: bold;">Nama Ibu</label>
                        <select class="form-control" name="id_ibu"  style="width: 100%;" required >
                            <option selected="selected" value="">-- Nama Ibu --</option>
                            @foreach($users as $datas)
                                <option value="{{ $datas->id_ibu}}">{{ $datas->nama_ibu }}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="form-group" style="font-weight: bold;>
                        <label for="tinggi_badan">Tinggi badan</label>
                        <input type="number" class="form-control" id="tinggi_badan" name="tinggi_badan" value="">
                    </div>
                    <div class="form-group" style="font-weight: bold;>
                        <label for="berat_badan">Berat Badan</label>
                        <input type="number" class="form-control" id="berat_badan" name="berat_badan" value="">
                    </div>
                    <div class="form-group" style="font-weight: bold;>
                        <label for="lila">LILA</label>
                        <input type="number" class="form-control" id="lila" name="lila" value="">
                    </div>
                    <div class="form-group" style="font-weight: bold;>
                        <label for="t_darah">Tekanan Darah</label>
                        <input type="text" class="form-control" id="t_darah" name="t_darah" value="">
                    </div>
                    <div class="form-group">
                        <label class="form-group" style="font-weight: bold; for="ket_imun">Keluhan</label>
                        <div class="form-group">
                            <textarea class="form-control" rows="4" id="keluhan" name="keluhan"></textarea>
                        </div>
                    </div>
                    <div class="form-group" style="font-weight: bold;>
                        <label for="tgl_periksa">Tanggal Periksa</label>
                        <input type="date" class="form-control" id="tgl_periksa" name="tgl_periksa" value="">
                    </div>                 
                    <div class="card-footer">
                        <button type="submit" class="btn btn-primary">Simpan</button>
                        <a href="{{ route('ibuhamil') }}" class="btn btn-warning">Kembali</a>
                    </div>
                </div>
            </div>        
        </div>
    </div>
</form>

2

Answers


  1. I think you are doing 1 or all of 3 things. First, you have an error in you html where you are missing a quote. Also you have an option that is "" an empty string and though the element is required. I believe that is still valid from an html perspective.

    <div class="form-group" style="font-weight: bold;>
    

    should be

    <div class="form-group" style="font-weight: bold;">
    

    Second, I would need to see your Database Schema, but unless your id_ibu is a string as well as a foreign key or key for something else. You probably don’t want to be setting it like that. Also from the database or MySql Error, you are plainly not passing it to the create function or I cannot remember if the id is a fillable attribute and unable to take that as the parameter.

    You should also validate the request data. In laravel you can reach for a validator where you can define the requirements and the type of data passed back foreach key. Also should update model to reflect $primarykey, $incrementing, and $keytype.

    Login or Signup to reply.
  2. 1.Check Request if the id_ibu is coming or not using dd($request->id_ibu)

    if value is coming then check the Ibuhamil.php you were added a $fillable property like $fillable = ['id_ibu'] orelse protected
    $guarded = [];
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search