Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

403 response in laravel

so this is my form script

<form action="{{ route('tambahproduk') }}" method="POST">
                @csrf
                <div class="modal-header">                      
                    <h4 class="modal-title">Tambah produk</h4>
                </div>
                <div class="modal-body">                    
                    <div class="form-group">
                        <label>Nama Produk</label>
                        <input name="nama_produk" type="text" class="form-control" required>
                    </div>
                    <div class="form-group">
                        <label>Harga</label>
                        <input name="harga" type="number" class="form-control" required >
                    </div>
                    <div class="form-group">
                        <label>Kategori</label>
                        <input name="kategori" type="text" class="form-control" required >
                    </div>
                    <div class="form-group">
                        <label  for="cars">Status :</label> <br>
                            <select name="status" id="cars">
                            <option value="Bisa dijual">Bisa dijual</option>
                            <option value="Tidak Bisa dijual">Tidak Bisa dijual</option>
                            </select>
                    </div>                  
                </div>
                <div class="modal-footer">
                    <a href="/">Kembali?</a>
                    <input type="submit" class="btn btn-success" value="Edit">
                </div>
            </form>

and this is my route script

Route::post('tambahproduk' ,[ProdukController::class, 'store'])->name('tambahproduk');

and this is my store function in ProdukController

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

   public function store(StoreprodukRequest $request)
    {
        $request->validate([
            'nama_produk' => 'required',
            'harga' => 'required|integer',
            'kategori' => 'required',
            'status' => 'required'
        ]);

        produk::create([
            'nama_produk' => $request->nama_produk,
            'harga' => $request->harga,
            'kategori' => $request->kategori,
            'status' => $request->status,
        ]);

        $produks = produk::all();
        return view('daftarproduk', compact('produks'));

    }

but it when i want to sumbit my form, its say 403 THIS ACTION IS UNAUTHORIZED.
but i dont use any authorization or authentication, all files include kernel.php its still laravael default.

is there something i miss?

>Solution :

In the StoreprodukRequest please make the following changes.

public function authorize()
{
    return true;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading