vl14b
vl14b

Reputation: 85

Update (CRUD) code doesnt have error but its doesnt work either

i need help with my code. I make a process to edit a data (update) in my CRUD.

This is my Update CRUD code in my controller :

public function update() {
$paket = array(
    'nama' => Input::get('nama'),
    'jumlah_user' => Input::get('jumlah_user'),
    'tanggal_mulai' => Input::get('tanggal_mulai'),
    'tanggal_terakhir' => Input::get('tanggal_terakhir')
  );
  DB::table('paket')->where('id','=',Input::get('id'))->update($paket);
  return Redirect::route('paket.index')->with('message','berhasil mengedit data');
}

and this is code in my edit form:

{{Form::open(array('url'=>'admin/prosesedit','method'=>'post','charset'=>'utf-8'))}}
{{Form::text("nama",$paket->nama,['placeholder'=>'Nama Paket','autocomplete'=>'off','required'])}}
{{Form::text("jumlah_user",$paket->jumlah_user,['placeholder'=>'Jumlah User','autocomplete'=>'off','required'])}}
{{Form::text("tanggal_mulai",$paket->tanggal_mulai,['placeholder'=>'Tanggal Mulai','autocomplete'=>'off','required'])}}
{{Form::text("tanggal_terakhir",$paket->tanggal_terakhir,['placeholder'=>'Tanggal Akhir','autocomplete'=>'off','required'])}}
{{Form::submit("Submit",["class"=>"btn btn-danger"])}}
{{Form::close()}}

This code somehow doesnt give an error. But it doesnt work too. Have any ideas? Newbie in Programming and Laravel here.

Upvotes: 1

Views: 285

Answers (1)

Sandeesh
Sandeesh

Reputation: 11936

Edit: Updated based on your route and controller information.

So here are few things you're doing wrong. Since you haven't posted your routes and controller logic, let me give you an example

Delete the following routes since you already have a resource controller with them.

Route::get('formedit/{id}', 'paketcontroller@edit');
Route::post('prosesedit', 'paketcontroller@update');

Controller

public function update($id) {
    $paket = array(
        'nama' => Input::get('nama'),
        'jumlah_user' => Input::get('jumlah_user'),
        'tanggal_mulai' => Input::get('tanggal_mulai'),
        'tanggal_terakhir' => Input::get('tanggal_terakhir')
    );
    DB::table('paket')->where('id', $id)->update($paket);
    return Redirect::route('paket.index')->with('message','berhasil mengedit data');
}

In your view

Change edit link from

href="formedit/{{$paket->id}}"

to

href="paket/edit/{{$paket->id}}"

Change

{{Form::open(array('url'=>'admin/prosesedit','method'=>'post','charset'=>'utf-8'))}}

to

{{Form::open(array('route' => array('paket.update', $paket->id), 'method' => 'PATCH', 'charset' => 'utf-8'))}}

Upvotes: 1

Related Questions