Adding form action in html in laravel

前端 未结 12 1226
深忆病人
深忆病人 2020-12-29 21:10

I am unable to pass url in views html form action tag.

相关标签:
12条回答
  • 2020-12-29 21:55

    if you want to call controller from form action that time used following code:

    <form action="{{ action('SchoolController@getSchool') }}"  >
    

    Here SchoolController is a controller name and getSchool is a method name, you must use get or post before method name which should be same as in form tag.

    0 讨论(0)
  • 2020-12-29 21:55

    Your form is also missing '{{csrf_field()}}'

    0 讨论(0)
  • 2020-12-29 21:56

    You need to set a name to your Routes. Like this:

    
        Route::get('/','WelcomeController@home')->name('welcome.home');
        Route::post('/', array('as' => 'log_in', 'uses' => 'WelcomeController@log_in'))->name('welcome.log_in');
        Route::get('home', 'HomeController@index')->name('home.index');
    
    

    I just put name on Routes that need this. In my case, to call from tag form at blade template. Like this:

    <form action="{{ route('home.index') }}" >
    

    Or, You can do this:

    <form action="/" >
    
    0 讨论(0)
  • 2020-12-29 21:58

    The following should work.

    {{  Form::open( array('url' => action('WelcomeController@log_in'), 'files'=>true,'method'=>'post') )  }}
    
    ...
    {{ Form::close() }}
    
    0 讨论(0)
  • 2020-12-29 22:04

    Laravel 5.8 Step 1: Go to the path routes/api.php add: Route::post('welcome/login', 'WelcomeController@login')->name('welcome.login'); Step2: Go to the path file view

    <form method="POST" action="{{ route('welcome.login') }}">
    </form>
    

    Result html

    <form method="POST" action="http://localhost/api/welcome/login">
    
    <form>
    
    0 讨论(0)
  • 2020-12-29 22:04

    Use action="{{ action('WelcomeController@log_in') }}"

    however TokenMismatchException means that you are missing a CSRF token in your form.

    You can add this by using <input name="_token" type="hidden" value="{{ csrf_token() }}">

    0 讨论(0)
提交回复
热议问题