-1

I create a route Route::post('/ddos/store','DdosController@store');

I also have a controller

public function store()
{

    dd("HERE");

    $ddos                = new Ddos;
    $ddos->ip            = $ip;
    $ddos->details       = $details;
    $ddoss->save();

    return $ddos;

}

I kept getting - when making a TEST post via postman

I suppose to see the text "HERE" from my controller.

What did I do wrong ?

code-8
  • 54,650
  • 106
  • 352
  • 604

2 Answers2

4

Postman is not sending a CSRF token in the request and your route is under the web routes group which applies the VerifyCsrfToken middleware

Either move your route to an api group or add it as an exception

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;

class VerifyCsrfToken extends Middleware
{
    /**
     * Indicates whether the XSRF-TOKEN cookie should be set on the response.
     *
     * @var bool
     */
    protected $addHttpCookie = true;

    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'ddos/store'
    ];
}
Salim Djerbouh
  • 10,719
  • 6
  • 29
  • 61
  • What Laravel version is your suggestion? Mine is 5.8. It looks like this ![](https://i.imgur.com/DfAXbge.png) – code-8 Sep 06 '19 at 01:11
  • You can always override the properties of the BaseVerifier – Salim Djerbouh Sep 06 '19 at 01:18
  • @kyo A base Laravel 5.8 install's VerifyCsrfToken looks like this: https://raw.githubusercontent.com/laravel/laravel/5.8/app/Http/Middleware/VerifyCsrfToken.php Yours came from somewhere else - perhaps the app was an older version and not updated? – ceejayoz Sep 06 '19 at 14:39
  • On the contrary, it's the latest 6.x – Salim Djerbouh Sep 06 '19 at 16:47
3

There is a middleware executed before dd line executed. It's called CSRF Protection. You can exclude it by adding this line in the app\Http\Middleware\VerifyCsrfToken.

    protected $except = [
        '/ddos/store',
    ];

If you insist to keep sending csrf token with postman, you can create tests case and save it in environment variable (which i suggest). This link might help you.

Hilman Nihri
  • 337
  • 5
  • 10