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

kathrinH's avatar

Request is empty

Hello,

i just started programming with Laravel 7 and i have a strange problem with requests.

I built a Form with laravelcollective to submit new series and set the form action to "store" in the "SeriesController", but if i do so i don't get the formdata by $request->all(). Only $request->getContent() shows me a string with the data. But $request->all() is empty.

The strange thing is, if i set the form action to create and put a route for post in the web.php, i get the data. $request->all() is filled. But i want to handle the saving process in the store action :/

It would be very nice if somebody could tell me where my mistake is or give me a hint on how to solve the problem. I'm out of ideas.

web.php:

    Route::resources([
        'series' => 'SeriesController']
    );

create.blade.php aka the form:

{!! Form::open(['action' => 'SeriesController@store', 'method' => 'post']) !!} <br />

	#some form fields#

{!! Form::close() !!}

The series controller:

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use App\Series;
use Barryvdh\Debugbar\Facade as Debugbar;

class SeriesController extends Controller
{
   ...
   
    public function create(Request $request){
        Debugbar::info($request->all());
        return view('Series/create');
    }
    
    public function store(Request $request){
        
        Debugbar::info($request->getContent());
        Debugbar::info($request->all());
		//return Redirect::action('SeriesController@index')
	}
	
}

I hope i put in all necessary information.

Hopefully KathrinH

0 likes
14 replies
Tray2's avatar

I recommend that you don't use the Laravelcollective and write regular html for your forms instead. They will be much easier to debug.

The problem is most likely in the form itself.

kathrinH's avatar

@tray2 i tried this, but it didn't work either :/ The problem seems to be somewhere else?

shez1983's avatar

can you spit out the actual HTML produced by doing inspect element? can you do php artisan route:list to get the route

kathrinH's avatar

The HTML of the Form is:

<form method="POST" action="domain/series" accept-charset="UTF-8">
<input name="_token" type="hidden" value="2U3CGu9kOMwN2r57IIbNaJfhiyWZe62jQENFTy22"> <br>

   <label for="name">Name</label> 
   	<input name="name" type="text" id="name"> <br>
    	
    <label for="author">Author</label>
   	<input name="author" type="text" id="author"> &nbsp;<br>
   
    <input type="submit" value="save"> <br>
	</form>

And the routes are:

| GET|HEAD  | series               | series.index    | App\Http\Controllers\SeriesController@index    |web,auth|

| POST      | series               | series.store    | App\Http\Controllers\SeriesController@store    |web,auth|

| GET|HEAD  | series/create        | series.create   | App\Http\Controllers\SeriesController@create   |web,auth|

| GET|HEAD  | series/{series}      | series.show     | App\Http\Controllers\SeriesController@show     |web,auth|

| PUT|PATCH | series/{series}      | series.update   | App\Http\Controllers\SeriesController@update   |web,auth|

| DELETE    | series/{series}      | series.destroy  | App\Http\Controllers\SeriesController@destroy  |web,auth|

| GET|HEAD  | series/{series}/edit | series.edit     | App\Http\Controllers\SeriesController@edit     |web,auth|
Tray2's avatar

This row

< form method="POST" action="domain/series" accept-charset="UTF-8"> 

Should be

< form method="POST" action="/series" accept-charset="UTF-8"> 
kathrinH's avatar

Shouldn't there be no difference wether its with the domain or without?

I changed it manually in the browser, but it seems to have no effect.

Tray2's avatar

This should work fine in your case.

<form method="POST" action="/series">
   @csrf
   <label for="author">Author</label>
   <input type="text" name="author"  required>
   <input type="submit" value="Save">
</form>
kathrinH's avatar

Unfortunately it doesen't. Still empty. There seems to be no redirect that would make me loose my form data.

And i also tried to configure the routes manually instead of using Route::resources

Route::get('/series', 'SeriesController@index')->name('home');

Route::post('/series', 'SeriesController@store')->name('store');

Route::get('/series/create', 'SeriesController@create')->name('create');

But this also didn't work...

But there is no way that the debug plugin is problem, right? Barryvdh\Debugbar

Tray2's avatar

What happens when you put this in your web routes file

Route::get('series/create', 'SeriesController@create');
Route::post('series', 'SeriesController@store');

And this in your SeriesController

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

    public function store(Request $request)
    {
        dd($request);
    }

and this in your resources/series/create.blade.php

<form method="POST" action="/series">
    @csrf
    <label for="author">Author</label>
    <input type="text" name="author"  required>
    <input type="submit" value="Save">
 </form>

It should give you something like this

Illuminate\Http\Request {#51 ▼
  #json: null
  #convertedFiles: null
  #userResolver: Closure($guard = null) {#207 ▼
    class: "Illuminate\Auth\AuthServiceProvider"
    this: Illuminate\Auth\AuthServiceProvider {#30 …}
    use: {▼
      $app: Illuminate\Foundation\Application {#1 …}
    }
    file: "/Users/tray2/Code/blaj/vendor/laravel/framework/src/Illuminate/Auth/AuthServiceProvider.php"
    line: "83 to 85"
  }
  #routeResolver: Closure() {#216 ▶}
  +attributes: Symfony\Component\HttpFoundation\ParameterBag {#53 ▼
    #parameters: []
  }
  +request: Symfony\Component\HttpFoundation\ParameterBag {#52 ▼
    #parameters: array:2 [▼
      "_token" => "DOUauBOghNGC3JbUbbnxa1f7BABuyo0jGdeCGUEp"
      "author" => "Test"
    ]
  }
  +query: Symfony\Component\HttpFoundation\ParameterBag {#59 ▶}
  +server: Symfony\Component\HttpFoundation\ServerBag {#55 ▶}
  +files: Symfony\Component\HttpFoundation\FileBag {#56 ▶}
  +cookies: Symfony\Component\HttpFoundation\ParameterBag {#54 ▶}
  +headers: Symfony\Component\HttpFoundation\HeaderBag {#57 ▶}
  #content: null
  #languages: null
  #charsets: null
  #encodings: null
  #acceptableContentTypes: null
  #pathInfo: "/series"
  #requestUri: "/series"
  #baseUrl: ""
  #basePath: null
  #method: "POST"
  #format: null
  #session: Illuminate\Session\Store {#235 ▼
    #id: "vwyfxdblBi8sMCHEyg3vZON5wnGCsI1nzPU0EJ7R"
    #name: "laravel_session"
    #attributes: array:3 [▶]
    #handler: Illuminate\Session\FileSessionHandler {#234 ▶}
    #started: true
  }
  #locale: null
  #defaultLocale: "en"
  -preferredFormat: null
  -isHostValid: true
  -isForwardedValid: true
  basePath: ""
  format: "html"
}
kathrinH's avatar

Its filled under request o.O

+request: Symfony\Component\HttpFoundation\ParameterBag {#51 ▼
    #parameters: array:2 [▼
      "_token" => "2U3CGu9kOMwN2r57IIbNaJfhiyWZe62jQENFTy22"
      "author" => "testing" 

But it is with the previous code, too. $request->all() is still empty in both cases.

But $request->author is working! According to the docu it should be $request->input('author'), but that doesn't work. I'm confused.

kathrinH's avatar

@jlrdw: I already watched many tutorials. The confusing part is, that i tried it like it was in the tutorials / the docu and it didn't work.

Tray2's avatar
Tray2
Best Answer
Level 73

I always use $request->author instead of $request->input('author') the few times I use the $request object

I never use $request->all() because that can potentially be quite dangerous if you don't know what you are doing.

And you should always validate the data sent before you store it.

I use this in one of my projects.

    public function store(Request $request)
    {
        $artist = $request->validate([
            'name' => 'required|unique:artists,name'
            'slug' => 'nullable'
        ]);
        $artist['slug'] = Str::slug($artist['name']);
        Artist::create($artist);
    }

I work with the validated array and not the request object once it passed the validations. That way I know that the data is correct.

1 like
kathrinH's avatar

@Tray2 I had a validator, but i removed it since the data i tried to validate was empty^^° Then i will work with $request->author, thank you very very much:)

Please or to participate in this conversation.