galih56
7 months ago

Why my update & insert form return url+token instead of insert/update data

Posted 7 months ago by galih56

I'm working on simple crud in laravel.I already built Controller,form, and model.But everytime i click the submit input.They always return this url and show 404 not found error,instead of insert the data.Can someone help me to find the problem?i have no clue about this part.

http://127.0.0.1:8000/POST?_token=bD5c3O0XpfTX7NWL7RA7wXSw3rWrQ12fbGLMw0kf&kode=galih&nama=galih&submit=Submit[^]

I set the route using Route::resource('urusan','MasterUrusanController)

Insert Form

{{ csrf_field() }} Kode Urusan Nama Urusan

Update Form

{{ method_field("PUT") }} {{ csrf_field() }} Kode Urusan Nama Urusan
       </form>

   </table>

class MasterUrusanController extends Controller { public function index() { $urusan=MasterUrusan::all(); return view('master_urusan.select',['urusan'=>$urusan]); //return View::make('master_urusan.select')->with('urusan',$urusan); }

public function create()
{
    return view('master_urusan.insert') ;
}

public function store(Request $request)
{
    $data=new MasterUrusan();
    $data->nama = $request->get('kode');
    $data->nama = $request->get('nama');
    $data->save();
    return redirect('/urusan');
}

public function edit($kode_urusan)
{

    
    $data = MasterUrusan::where('kode_urusan','=',$kode_urusan)->firstOrFail();
    return view('master_urusan.update', ['urusan' => $data]);
}
public function update(Request $request,$kode_urusan)
{ 
    $data = MasterUrusan::where('kode_urusan','=',$kode_urusan)->firstOrFail();
    $data->nama = $request->get('nama');
    $data->save();
    return redirect('/urusan');
    
}

public function destroy($kode_urusan)
{
    $data = MasterUrusan::where('kode_urusan','=',$kode_urusan)->firstOrFail();
    $data->delete();
    return redirect('/urusan');
}

}

Please sign in or create an account to participate in this conversation.