Problems with laravel Resource Controller

1.laravel created a new resource controller

class UserController extends Controller
{

    public function index()
    {
        echo "i am index";
    }


    public function create()
    {
        echo "i am create";
    }

    public function store(UserRequest $request)
    {
        echo "i am store";
    }

    public function show(User $user)
    {
        echo "i am show";
    }

    public function edit(User $user)
    {
        echo "i am  edit";
    }

    public function update(Request $request, User $user)
    {
        echo "i am update";
    }


    public function destroy(User $user)
    {
        echo "i am destroy";
    }
}

use postman to test according to the corresponding resource routing on the network

clipboard.png


post /user,laravel postcsrf,,http/middleware/verifycsfToken.php


csrf,edit

clipboard.png

there are several problems:
1. Why do you have this problem? shouldn"t you access the store method? why do you visit edit?
2. How to deal with the problem of csrf when testing post mode in postman

Dec.01,2021

if you are doing an API server. Just write the route in routers/api.php


if you read it wrong, I'll try and answer again.


  1. the first question is temporarily unknown
  2. the second problem can be solved by setting csrf whitelist , which can be url or route name in the except array, thus avoiding csrf verification
  3. .
class VerifyCsrfToken extends Middleware
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'stripe/*',
        'http://example.com/foo/bar',
        'http://example.com/foo/*',
    ];
}
Menu