Vipertecpro
Vipertecpro

Reputation: 3274

Can we pass PUT,PATCH and DELETE request via route() method from blade in anchor tag?

Rephrasing Question : I know how it works via form submit and ajax request, 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.

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

<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);
    }
}

This is how i'm calling route

Route::resource('employees','EmployeeController');

I can do this to achieve what i want

Route::get('employees/{employees}','EmployeeController@destroy')->name('employees.destroy');
Route::resource('employees','EmployeeController')->except([
    'destroy'
]);

Upvotes: 0

Views: 1112

Answers (1)

Mohammed Sabir
Mohammed Sabir

Reputation: 354

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>

Upvotes: 2

Related Questions