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

Ilovethekino's avatar

post/put/patch doesn't work on server

When I try to update a file it gives me status code 302 but on my localhost it works fine. And when I tried todo a post request I get status code 403 forbidden. I use shared hosting.

route Route::resource('test','TestController');

controller store and update

public function store(Request $request)
    {  print_r('store');return;}

public function update(Request $request, $id)
    { print_r('update');return;}

blade

<form enctype="multipart/form-data" action="{{route('test.update',$file->id)}}" method="post" role="form">
    {{ method_field('PUT') }}
    @csrf
    <input type="text" name="title" value="<?php echo $file->filename ?>"></input><br><br>
    <textarea style="width: 100%;height: 90%;"name="comment">{{$file->msg}}</textarea>
    <input type="submit" value="Update" name="code"></input>
</form>

when I press the button with the post it redirects to the /test page and with the update it just refreshes the /test/1/edit

edit: I found out that the bug only apears if the title/comment in the form contain the text @import it never even reaches the controller just reloads the page.

0 likes
12 replies
jlrdw's avatar

Check your htaccess file, check routes, check that letter size is right, linux is case sensitive. After any changes, clear cache, etc.

Make sure any folder being written to has correct permissions.

Usually forbidden means you're not allowed therefore that's why I said check letter size, you could have a bad route.

NOMGUY's avatar

For Update, you should use PATCH. You can check all the form submissions by,

php artisan route:list

There you can find that for update we should use PATCH and for storing the data we should use POST.

Ilovethekino's avatar

I think my htaccess file is fine I didnt change anything in it really. the server sometimes write something in there but I don't know what most of it means.

htaccess file

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

</IfModule>

<Files 403.shtml>
order allow,deny
allow from all
</Files>

my route seems fine to me aswell this is what it shows in the route list

 PUT|PATCH | test/{test}                 | test.update        | App\Http\Controllers\TestController@update

patch gives me the same status code as put "status code 302 Found" and doesnt do what its suppose todo it just stays on the same page nothing changes

Cronix's avatar

In your browser, view the source of the html page with the form. Does the form html look correct? Is the @csrf field being generated correctly (looks like a regular form field)?

Is the view actually a blade template (has xxx.blade.php)?

Are you passing $file to the view that is creating the form (you're not showing that controller method)?

Ilovethekino's avatar

Yes the input of the csrf is created

<input type="hidden" name="_token" value="token would have been here">

and the $file data is all send correctly its a test.blade.php file everything works fine until I click on the update button then it returns status code 302

newbie360's avatar

$file->id))

<form enctype="multipart/form-data" action="{{route('test.update',$file->id))}}" method="post" role="form">
Ilovethekino's avatar

thats just a typo on this post the blade doesnt have that.

Ilovethekino's avatar

Apperntly the error only apears when the title/comment contain the text @import does anyone know what could cause it?

jlrdw's avatar

You said

but on my localhost it works fine

Did you even check like I suggested for correct letter size.

If you have the same correct code on local and production it should work.

Windows

a equals A

Linux

a does not equal to A

Ilovethekino's avatar

I did and I replied that im not sure of my htaccess is correct since I have no clue how it should be written thats why I replied with my htaccess file

btw how do you quote stuff?

jlrdw's avatar

To quote what someone said

A greater than symbol, a space, and the text.

To highlight a word

use a backtick, the word, and another backtick.

Your local htaccess should work on production also. I have never had to change it.

Please or to participate in this conversation.