Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Christianus's avatar

@Snapey This one right ? action="/editkeluhan/{{$keluhan->id }}" it said error 404 not found url sir

in my Controller, yup i've delete it now :)

so what should i do, just a little bit more to solve this hufft

Snapey's avatar

Look in browser tools

Switch to network tab

post form. Make sure POST is made to /editheluhan/5 (example, 5 is the id number)

make sure in the request that is sent to the server you have the hidden _method field, the hidden _csrf field and your form data

Christianus's avatar

@Snapey when i click button the tab url will be http://localhost/editkeluhan/%7B%7B$keluhan-%3Eid%7D

yup sir seems like i've or maybe something that i missed again

<form class="form-horizontal" role="form" method="POST" action="{{ '/editkeluhan/{{$keluhan->id}' }}" enctype="multipart/form-data">
                        {{ csrf_field() }}

                        <div>
                            <input name="_method" type="hidden" value="PATCH">
                        </div>

This is the route

Route::get('editkeluhan/{id}','AdminController@editkeluhan');
Route::resource('/editkeluhanadmin', 'AdminController@updatekeluhanadmin');
Snapey's avatar

Yes, action is still wrong

action="{{ '/editkeluhan/{{$keluhan->id}' }}"

should be

action="/editkeluhan/{{$keluhan->id}}"
Christianus's avatar

@Snapey unfortunately the result was same error 404 Object not found... omg i really confused why this is happen

oh wait wait... its change now the url error was http://localhost/editkeluhan/1

my routes

//edit keluhan
Route::get('editkeluhan/{id}','AdminController@editkeluhan');
Route::resource('/editkeluhanadmin', 'AdminController@updatekeluhanadmin');
Snapey's avatar

Please read about resource controllers

You cannot use Route::resource and then specify a specific method

Go back to your patch route that you had before

Route::patch('/editkeluhan/{id}', 'AdminController@updatekeluhanadmin');
Snapey's avatar

specify form action EXACTLY as stated

Snapey's avatar

By the way, you need to fix your local web server. You should not see public in your routes. This will explain a lot of errors.

Your web server document root needs to be the public folder.

Christianus's avatar

'specify form action EXACTLY as stated' what is that mean ? what should i do or change bro ?

umm actually im not make the project from beginning so idk about root web server, i just resume my upperclassmen, so its hard to me to understand this all code sorry

Btw, can i solve this problem without fix my local web server firsh @snapey ? :(

Christianus's avatar

@vipin93 @Snapey I've read it all but still not work, is my code too hard ? or is it because of little mistake or what, please please help me, i gonna surrender but now i still trying

Christianus's avatar

@vipin93 @Snapey I've read all the doc but still cant solve this, i'm gonna surrender but i still trying right now, please help me again guys

vipin93's avatar

why not u using only

Route::resource('editkeluhanadmin', 'AdminController');

run php artisan route:list and see where what route action its using in controller for your CRUD methods why u making so complicate

Snapey's avatar

because you are having problems with the web serving, any routes that are declared as 'editkeluhanadmin' or '/editkeluhanadmin' are going to go the the wrong place.

As a workaround, you can create your form action like this;

<form class="form-horizontal" role="form" method="POST" action="{{ action('AdminController@updatekeluhanadmin',(['id'=>$keluhan->id]) }}"  enctype="multipart/form-data">

This will create a URL using the correct root folder of your site as it is configured now.

1 like
Christianus's avatar

@Snapey that's great seems like we will end it as soon as possible :) now its not error even i use patch on the route instead of resource :) but the data is not update db yet sir, is it because or $r ?

This is current Route

Route::get('editkeluhan/{id}','AdminController@editkeluhan');
Route::patch('editkeluhanadmin/{id}', 'AdminController@updatekeluhanadmin'); //Using Patch Now

This is AdminController

    public function updatekeluhanadmin(Keluhan $keluhan, Request $r){
        $halaman = 'tindaklayanan';
        $keluhan->update($r->all());
        return redirect('/');
    }

and my current view that has been repair

<form class="form-horizontal" role="form" method="POST" action="{{ action('AdminController@updatekeluhanadmin',['id'=>$keluhan->id]) }}"  enctype="multipart/form-data">

                        {{ csrf_field() }}

                        <div>
                            <input name="_method" type="hidden" value="PATCH">
                        </div>

                        <div class="form-group">
                            <label for="unit" class="col-md-4 control-label">Pilih Unit</label>
                            <div class="col-md-6">
                                <select name="unit">
                                    <option value="Quality Control">Quality Control</option>
                                    <option value="Customer Service">Customer Service</option>
                                    <option value="PPIC">PPIC</option>
                                    <option value="Produksi 1">Produksi 1</option>
                                    <option value="Produksi 2">Produksi 2</option>
                                    <option value="Finishing">Finishing</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="jenis_keluhan" class="col-md-4 control-label">Jenis Keluhan</label>
                            <div class="col-md-6">
                                <select name="jenis_keluhan">
                                    <option value="Reject">Komplain</option>
                                    <option value="Complain">Reject</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="status" class="col-md-4 control-label">Status Keluhan</label>
                            <div class="col-md-6">
                                <select name="status">
                                    <option value="Pending">Pending</option>
                                    <option value="Proses">Proses</option>
                                    <option value="Selesai">Selesai</option>
                                </select>
                            </div>
                        </div>

                        <div>
                            <label for="produk" class="col-md-4 control-label" name="produk">Nama Produk</label>

                            <div class="col-md-6">
                                <input id="produk" type="text" class="form-control" name="produk" value="{{old('produk', $keluhan->produk)}}" required="true">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="area" class="col-md-4 control-label">Pilih Area</label>
                            <div class="col-md-6">
                                <select name="area">
                                    <option value="Jawa Barat">Jawa Barat</option>
                                    <option value="Jawa Tengah">Jawa Tegah</option>
                                    <option value="Jawa Timur">Jawa Timur</option>
                                    <option value="Luar Area Jawa">Luar Area Jawa</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="kategori" class="col-md-4 control-label">Kategori</label>
                            <div class="col-md-6">
                                <select name="kategori">
                                    <option value="Keluhan Pelanggan">Keluhan Pelanggan</option>
                                    <option value="Survey Pelanggan">Survey Pelanggan</option>
                                    <option value="Inspeksi">Inspeksi</option>
                                    <option value="Audit">Audit</option>
                                    <option value="Gagal Proses">Gagal Proses</option>
                                    <option value="Analisa Data">Analisa Data</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="masalah" class="col-md-4 control-label" required="true">Keluhan Pelanggan</label>
                            <textarea style="resize: none; height: 100px" name="masalah">{{old('masalah', $keluhan->masalah)}}</textarea>
                        </div>

                        <div class="form-group">
                            <label for="keterangan" class="col-md-4 control-label">Keterangan Tambahan</label>
                            <textarea style="resize: none; height: 100px" name="keterangan">{{old('keterangan', $keluhan->keterangan)}}</textarea><p>
                        </div>


                        <div align="center">
                            <div>
                                <h7><b>Tambahkan Gambar</b></h7>
                                <h7>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</h7>
                                <h7><b>Disetujui Oleh (PuraBox)</b></h7>
                            </div>
                            <div>
                                <input class="field" name="gambarkeluhan" type="file" required="true">
                                <input class="field" name="ttdcus2" type="file" required="true">
                                <br>
                                <br>
                                <br>
                                <br><br>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-4" align="center">
                                <button type="submit" class="btn btn-primary">
                                    <i class="fa fa-btn fa-sign-in"></i> Lanjut
                                </button>                            
                            </div> 
                        </div>
                    </form>
Snapey's avatar

I suggest you dd($r) in your controller and check exactly what you received.

Writing data to the model requires $fillable setup - have you done that?

Do your form field names match the columns in your model?

For instance, you have a field called unit and it is of type string and is listed in the $fillable array?

Christianus's avatar

@Sanpey i've add dd($r) and this is the result

Request {#42 ▼
  #json: null
  #convertedFiles: null
  #userResolver: Closure {#201 ▶}
  #routeResolver: Closure {#213 ▶}
  +attributes: ParameterBag {#44 ▶}
  +request: ParameterBag {#43 ▶}
  +query: ParameterBag {#50 ▶}
  +server: ServerBag {#47 ▶}
  +files: FileBag {#46 ▶}
  +cookies: ParameterBag {#45 ▶}
  +headers: HeaderBag {#48 ▶}
  #content: null
  #languages: null
  #charsets: null
  #encodings: null
  #acceptableContentTypes: null
  #pathInfo: "/editkeluhanadmin/1"
  #requestUri: "/simmb/public/editkeluhanadmin/1"
  #baseUrl: "/simmb/public"
  #basePath: null
  #method: "PATCH"
  #format: null
  #session: Store {#236 ▶}
  #locale: null
  #defaultLocale: "en"
}

Yup, im really sure :) cause my store (add into DB) is work fine

this is it sir, my Keluhan models, and my field name was match with column in my model

<?php

namespace App\Http\Models;

use Illuminate\Database\Eloquent\Model;

class keluhan extends Model
{
    protected $fillable = [
        'tanggal',
        'produk',
        'username',
        'email_address',
        'area',
        'kategori',
        'jenis_keluhan',
        'masalah',
        'keterangan',
        'status',
        'opt',
        'ttd_pemohon',
        'ttd_setuju',
        'unit'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $table = 'keluhans';
}
cviv's avatar

Your route is using PATCH

Route::patch('editkeluhanadmin/{id}', 'AdminController@updatekeluhanadmin'); //Using Patch Now

but your Form is Using POST

<form class="form-horizontal" role="form" method="POST" action="{{ action('AdminController@updatekeluhanadmin',['id'=>$keluhan->id]) }}"  enctype="multipart/form-data">

Be mindful to sync them.. If you use patch in your controller, your form method should also be patch. or if you use post in your controller, your form method should also be post.

cviv's avatar

Ok. Did you ask your form which one is he going to follow? Is it the Post or the Patch?

Christianus's avatar

@cviv i confuse why the data not update on DB bro, look at my code above on controller & view, why $keluhan->update($r->all()); not working

vipin93's avatar

here u are using route model binding so instead of {id} to {keluhan} and change action to simple "editkeluhanadmin/{{$keluhan->id}}" and add {{method _ field ('patch')}}

1 like
Christianus's avatar

Yeah, its work !! yeah yeah we did it in the 4th day... special thanks to @vipin93 @Snapey you both are great, hope when i'm facing another problem you guys want to help me again and not get bored hearing my question :)

But who should i give 'best reply' ?

Christianus's avatar

@vipin93 @Snapey last one, its not update the file input, what wrong with this (Sorry my code is disorganized)

My Program -> Input File (image) -> validator -> store image into filesystem -> save name into DB

My Program -> Update -> Filename not changed & not stored on filesystem

keluhan.blade.php

<input class="field" name="ttd_pemohon" type="file" required="true">
                                <input class="field" name="ttd_setuju" type="file" required="true">

Validator & function Insert to DB (UserController.php)

public function insertkeluhan(Request $request){
        
        $keluhan = keluhan::create($request->all());
        $keluhan->tanggal = carbon::now();
        $keluhan->username;
        $keluhan->email_address;
        $keluhan->status = 'Pending';

            $ttd1post = $request->only('ttd_pemohon');
            $ttd1rules = array('ttd_pemohon' => 'mimes:jpeg,jpg,png|required|max:10240');
            $ttd1validator = Validator::make($ttd1post, $ttd1rules);
            if ($ttd1validator->fails()) {
                    return redirect('/layanankonsumen');
            } else {
                $ttd1Name = $request->file('ttd_pemohon')->getClientOriginalName();
                $path = base_path() . '/public/img/ttd';
                $request->file('ttd_pemohon')->move($path , $ttd1Name);
                $keluhan->ttd_pemohon = $ttd1Name;
            }

            $ttd2post = $request->only('ttd_setuju');
            $ttd2rules = array('ttd_setuju' => 'mimes:jpeg,jpg,png|required|max:10240');
            $ttd2validator = Validator::make($ttd2post, $ttd2rules);
            if ($ttd2validator->fails()) {
                    return redirect('/layanankonsumen');
            } else {
                $ttd2Name = $request->file('ttd_setuju')->getClientOriginalName();
                $path = base_path() . '/public/img/ttd';
                $request->file('ttd_setuju')->move($path , $ttd1Name);
                $keluhan->ttd_setuju = $ttd2Name;
            }   

        $keluhan->save();
        return redirect('/');
    }

And last my AdminController

public function lihatkeluhan(){
        $halaman="tindaklayanan";
        $keluhan_list=DB::table('keluhans')
        ->select(DB::raw('id,tanggal,produk,username,area,masalah,status'))->get();
        $rows=DB::table('keluhans')->orderby('id','asc')->get();
        return view('layanankonsumen.daftarkeluhan',compact('halaman','rows','id','tanggal','produk','username','area','kategori',
            'jenis_keluhan','masalah','status','ttd_setuju'));

public function editkeluhan($id){
        $halaman="tindaklayanan";
        $keluhan=keluhan::findOrFail($id);
        return view('layanankonsumen.editkeluhan',compact('keluhan','halaman'));
    }

    public function updatekeluhanadmin(Keluhan $keluhan, Request $r){
        $halaman = 'tindaklayanan';
        //dd($r);
        $keluhan->update($r->all());
        return redirect('/');

Please help me how to make it store into filesystem when its gonna be updated and change the name in DB too, second my validator is not perfect, if its fail it return BUT the data still stored on DB, how to fix it @vipin93 @Snapey

Please or to participate in this conversation.