Ad

Laravel5.7 Routing Using Route:match Not Working

- 1 answer

I'm using Laravel 5.7 I'm trying to route my function for get and post. I want to load a view and post a form. As I have studied

Route::match(['GET','POST'], '/', [email protected]);
Route::any('/', [email protected]);`

one of these should work.

But its not working for me,is there any other way or I'm doing something wrong?

UPDATE

Route to admin:

Route::match(['get','post'], 'cp/', '[email protected]');

Function in Admin controller:

public function test( Request $request){

    $data=array();

    if ($request->isMethod('POST')) {
        echo "here it is";
        exit;
    }else{ 
        echo "still in get!";
    }
    return view('admin/login',  $data);
}

And my view in short is something like this:

<form  action="{{ url('/cp') }}" method="POST">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
<form>
Ad

Answer

Can you try changing

Route::match(['GET','POST'], '/', [email protected]);

to

Route::match(['GET','POST'], '/', '[email protected]');

OR

Route::any('/', [email protected]);

to

Route::any('/', '[email protected]');

The second param should be wrapped in quotes!

UPDATE:

Your route match code should be something like this :

Route::match(array('GET', 'POST', 'PUT'), "/", array(
    'uses' => '[email protected]',
    'as' => 'index'
));
Ad
source: stackoverflow.com
Ad