skip to Main Content

I try to make a simple form.
When i want to make form for edit the data, it always pop up error like that.

This is my edit form

@section('title', 'Form Edit Mata Kuliah')

@section('header')
<h1 class="page-header"><b>Form Mata Kuliah</b></h1>
{{ Form::open(array('url' => 'updatekuliah')) }}
@endsection

@section('navigation')
<p>Edit Data Kuliah</p>
@endsection

@section('content')
@foreach($datakuliah as $p)
<div class="form-group row">
    <div class="col-md-4">
        {{ Form::label('kodematakuliah', 'Kode Mata Kuliah') }}
    </div>
    <div class="col-md">
        {{ Form::label('',':') }}
    </div>
    <div class="col-md-7">
        {{ Form::text('kodematakuliah', $p->kodematakuliah_db, array('class' => 'form-control', 'placeholder' => 'Masukkan Kode Mata Kuliah')) }}
    </div>
</div>
<br>
{{ Form::submit('Kirim', array('class' => 'form-control')) }}
{{ Form::close() }}
@endforeach
@endsection

This is my controller

namespace AppHttpControllers;
use AppHttpControllersController;
use IlluminateSupportFacadesRedis;
use IlluminateHttpRequest;
use IlluminateSupportFacadesDB;

class Pertemuan6Controller extends Controller
{
    public function tampilkanformedit($kodeedit)
    {
        $varkuliah = DB::table('tabel_pertemuan6')->where('kodematakuliah_db', $kodeedit)->get();
        return view("pertemuan6.formedit", ['datakuliah' => $varkuliah]);
    }
}
?>

This is my route

Route::get('/formkuliah', [Pertemuan6Controller::class, 'tampilkanformtambah']);
Route::get('/editkuliah/{kodeedit}', [Pertemuan6Controller::class, 'tampilkanformedit']);

Route::post('/insertkuliah', [Pertemuan6Controller::class, 'insertdatakuliah']);
Route::post('/updatekuliah', [Pertemuan6Controller::class, 'updatedatakuliah']);
Route::get('/deletemhs/{nimhapus}', [Pertemuan6Controller::class, 'deletedatamahasiswa']);

Anyone know how to handle that error? Thanks before

2

Answers


  1. You can pass only array and collections to foreach loop. Actually get method should return empty array if it doesn’t have any value. If I’m not wrong, your query passes NULL. That’s why you are getting this result. Check the value before passing it to the view.

    Login or Signup to reply.
  2. This should return collection and not null:

    `$results = DB::table('tabel_pertemuan6')->where('kodematakuliah_db',` `$kodeedit)->get();`
    

    Do

    var_dump($results);
    

    or

    dd($results);
    

    and check if you get expected values. Expected is collection. Check here for more info here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search