title: Laravel 8 API post request objest are empty
body: <p>I am new to Laravel (version 8), and not a big fun of php, but now I need to write a simple API in php, and I have problems.</p>
  <p>First, I can login, I got the token. That's a good part.</p>
  <p>My route configuration in api.php looks like this:</p>
  <pre><code>use Illuminate\Http\Request;
  use Illuminate\Support\Facades\Route;
  
  use App\Http\Controllers\Api\SecurityController;
  use App\Http\Controllers\Api\MessageController;
  
  Route::post('/login', [SecurityController::class, 'login']);
  Route::get('/messages', [MessageController::class, 'index']);
  Route::post('/messages', [MessageController::class, 'store']);
  
  
  /* Message controller routes */
  /* !! if definied like this, not even one /messages endpoint is hited from Postman !!*/
  // Route::middleware('auth:sanctum')-&gt;group(function ()
  // {
  //     Route::apiResource('messages', MessageController::class);
  // });
  
  
  /* Security controller routes */
  Route::middleware('auth:sanctum')-&gt;get('/user', function (Request $request)
  {
      return $request-&gt;user();
  });
  </code></pre>
  <p>My controler for messages:</p>
  <p>namespace App\Http\Controllers\Api;</p>
  <pre><code>use App\Http\Controllers\Controller;
  use Illuminate\Http\Request;
  use App\Models\Message;
  use App\Http\Resources\Message as MessageResource;
  use App\Http\Resources\MessageCollection;
  use App\Helpers\HashGenerator;
  
  class MessageController extends Controller
  {
  /**
       * Store a newly created resource in storage.
       *
       * @param  \Illuminate\Http\Request  $request
       * @return \Illuminate\Http\Response
       */
      public function store(Request $request)
      {
          $hash = HashGenerator::generateRandomString($request-&gt;text, 10);
  
          $message = Message::create
          ([
              'uniq' =&gt; $hash,
              'text' =&gt; $request-&gt;text,
              'imageLink' =&gt; $request-&gt;imageLink,
              'typeID'  =&gt; $request-&gt;typeID,
              'answerTypeID' =&gt; $request-&gt;answerTypeID
          ]);
  
         return new MessageResource($message);
      }
  }
  </code></pre>
  <p>Now the problem is that $request are empty, and I got the following message:</p>
  <p><em>Integrity constraint violation: 1048 Column 'text' cannot be null (SQL: insert into <code>messages</code> (<code>uniq</code>, <code>text</code>, <code>imageLink</code>, <code>typeID</code>, <code>answerTypeID</code>, <code>updated_at</code>, <code>created_at</code>) values (44f3d0c26f9f8b6338d82cd2ab8ac402, ?, ?, ?, ?, 2021-01-30 16:08:54, 2021-01-30 16:08:54))</em></p>
  <p>The  <code>text</code>, <code>imageLink</code>, <code>typeID</code>, <code>answerTypeID</code> fields are empty. If I just tell the function to return the $request it returns [] as an answer.</p>
  <p>So what am I doing the wrong way?
  What did I miss in the routing?
  Why is my $request empty?</p>
  <p>I am testing it from Postman. The object that I am sending are:</p>
  <pre><code>{
    &quot;text&quot; : &quot;{{$randomLoremParagraphs}}&quot;,
    &quot;imageLink&quot; : &quot;{{$randomAbstractImage}}&quot;,
    &quot;typeID&quot; : &quot;{{$randomInt}}&quot;,
    &quot;answerTypeID&quot; : &quot;{{$randomInt}}&quot;
  }
  </code></pre>
  <p>and if I check in console, the request body is there:</p>
  <pre><code>text: &quot;Provident libero voluptatem a aut quis occaecati ut nesciunt. Et eius et. Velit blanditiis quo nobis. Odit officiis cupiditate et fuga dolore necessitatibus vero officiis. Eum ut eius sint magnam et ut iure. Non totam deserunt totam veniam.
   
  Delectus suscipit est. Ut adipisci asperiores illo. Quas quia consectetur aliquam quidem. Commodi dolores architecto magnam.
   
  Necessitatibus voluptatem et quidem ut in reprehenderit alias eaque quia. Velit dolorem facere. Ut itaque vel sunt quod possimus et quo ut voluptatem. Nobis porro veritatis. Ut et modi atque praesentium voluptate voluptate id. Sunt non voluptatibus.&quot;
  imageLink: &quot;http://placeimg.com/640/480/abstract&quot;
  typeID: &quot;397&quot;
  answerTypeID: &quot;319&quot;
  </code></pre>
  <p>In header I set the:</p>
  <pre><code>Content-Type : application/json
  Authorization : Bearer 18|4i3pFHEYcMnG34BTSCKuStDcDPQBot12THXOAu9d
  </code></pre>
  <p>With or without the JWT is is not working.
  At the end I need all the MessagesController enpoints to be protected.</p>
  <p>My Message class:</p>
  <pre><code>namespace App\Models;
  
  use Illuminate\Database\Eloquent\Factories\HasFactory;
  use Illuminate\Database\Eloquent\Model;
  
  class Message extends Model
  {
      use HasFactory;
  
      protected $fillable =
      [
          'uniq', 'text', 'imageLink', 'typeID','answerTypeID'
      ];
  
      public function user()
      {
          return $this-&gt;belongsTo(\App\Models\User::class);
      }
  
      public function messageType()
      {
          return $this-&gt;hasOne(\App\Models\MessageType::class);
      }
  
      public function messageAnswerType()
      {
          return $this-&gt;hasOne(\App\Models\MessageAnswerType::class);
      }
  }
  </code></pre>
  <p>thnx</p>