我怎样才能将它转换为laravel

时间:2018-01-25 17:17:51

标签: laravel

我有一个简单的问题。 我如何将其转换为laravel?

Native php

<form method="post">
<input type="button" name="button">
</form>
<?
if(isset($_POST["button"])){
    echo "its work";
}
?>

1 个答案:

答案 0 :(得分:0)

Holy Moly ....

  

我强烈建议您阅读documentation

路由/ web.php

<?php    
Route::get('form', 'TestController@form')->name('form');
Route::post('form', 'TestController@submit');

应用\ HTTP \控制器\ TestController.php

<?php
namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Request;

class TestController extends Controller
{

    public function form()
    {
        return view('form');
    }

    public function submit(Request $request)
    {
        $validator = $request->validate([
            // validation here
            // 'input' => 'rule'
        ]);

        dd($validator);
    }

}

资源/视图/ form.blade.php

<form method="post" action="{{ route('form') }}">
    {{ csrf_field() }}
    <input type="submit" name="button">
</form>