Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
521 views
in Technique[技术] by (71.8m points)

laravel - 我们可以通过route()方法从刀片传递请求吗?(Can we pass post request via route() method from blade?)

Rephrasing Question : I know how it works via form, i've been looking that if there is any way we can send "DATA", simply by calling URL (mentioned below) for PUT,PATCH and DELETE and csrf token will be taken from Kernel > Middleware not via form submit.

(改写问题 :我知道它是如何通过表单工作的,我一直在寻找是否有任何方法可以通过简单地通过调用URL(如下所述)来发送“数据”来获取PUT,PATCH和DELETE,csrf令牌将从内核>中间件,不通过表单提交。)

I've been trying to use this method destroy() DELETE method to be run from blade file like this

(我一直在尝试使用这种方法destroy() DELETE方法从刀片文件运行,像这样)

<a class="p-2" href="{{ route('employees.destroy',[$key->id]) }}">Remove</a>

Can we override this method ?

(我们可以重写此方法吗?)

if (! function_exists('route')) {
    /**
     * Generate the URL to a named route.
     *
     * @param  array|string  $name
     * @param  mixed  $parameters
     * @param  bool  $absolute
     * @return string
     */
    function route($name, $parameters = [], $absolute = true)
    {
        return app('url')->route($name, $parameters, $absolute);
    }
}
  ask by Vipertecpro translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Might be your solution:

(可能是您的解决方案:)

<form action="{{ route('employees.destroy', ['id' => $key->id]) }}" method="post">
    <input class="btn btn-default" type="submit" value="Delete" />
    @method('delete')
    @csrf
</form>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...