6

Mates, I'm developing a Backbone/Laravel application. When I try to send a POST request to a certain resource, it returns me 301 status with no response, regardless that on the controller i'm printing a 'hello world', to check if it's getting to that point.

Here's some code...

public function store()
    {
        //
        return 'hello world';
    }

This is the routes.php

Route::group(array('before' => 'auth'), function()
{
    Route::get('/', 'SitesController@index');
    Route::resource('rooms', 'RoomsController');

});

So, when I make a POST request to

rooms

With some info to save, it gives me back 301 status with no response at all.

Any idea what am I doing wrong?

Thanks in advance!

Pablo
  • 1,173
  • 4
  • 18
  • 46

3 Answers3

14

Solved!

On backbone collection configuration, I had url parameter with '/' at the end.

rooms/

Deleted that slash and now it works fine. Hope someone find's this helpful

Pablo
  • 1,173
  • 4
  • 18
  • 46
  • I am using resource routes, for example `Route::resource('suppliers', SupplierController::class);` so the route list is generating automatically, in that case what should be done? – Sharif May 31 '23 at 21:10
3

(Adding this answer in case anyone has the same issue as me)

In my case I had a resource videos which gave the exact same problem. The reason was that I also had a directory on the server /videos/ (with files in it) which the server tried to point me to before it let Laravel direct it to the controller.

Niels
  • 1,340
  • 2
  • 15
  • 32
0

For some reason, posting to "image" in Laravel, even without a trailing "/" gives me a 301 Moved Permanently HTTP response.

I don't have an "image" folder in my public directory and still don't understand why the redirect occurs.

Changing the request to "foo" seems to work fine.

So if you found this page because you're trying to store an image restfully, try something like this:

Route::resource('api/image', 'ImageController');
Rann Lifshitz
  • 4,040
  • 4
  • 22
  • 42
Luke Diebold
  • 113
  • 1
  • 9