如何在Laravel 5.0中从视图传递数据到控制器?

7

我是一名新手,正在学习laravel,尝试从视图中将数据传递给控制器,但出现了一些错误。我已经搜索过了但没有找到解决方法。请查看我的代码并指出我的错误在哪里?

demoview.blade.php 代码

echo Form::open(array( 'method' => 'post','action' => 'DemoController@savess'));
echo Form::label('name', 'Name');
echo Form::text('name');
echo Form::label('email', 'E-Mail Address');
echo Form::text('email');
echo  Form::close();

DemoController.php 代码

    namespace App\Http\Controllers;

    use Illuminate\Http\Request;

class DemoController extends Controller {

    /*
    |--------------------------------------------------------------------------
    | Welcome Controller
    |--------------------------------------------------------------------------
    |
    | This controller renders the "marketing page" for the application and
    | is configured to only allow guests. Like most of the other sample
    | controllers, you are free to modify or remove it as you desire.
    |
    */

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    /**
     * Show the application welcome screen to the user.
     *
     * @return Response
     */
    public function demofunction()
    {
        $users = \DB::table('user')->get();
        foreach ($users as $user)
        {
            echo  $user->name;
            echo  $user->email;
        }

        return view('demoview');
    }

    public function savess(){
    }
}

Routes.php 代码

Route::get('demo', 'DemoController@demofunction');

错误:

ErrorException in compiled.php line 8658:
Action App\Http\Controllers\DemoController@savess not defined. (View: E:\xampp\htdocs\ayaz\resources\views\demoview.blade.php)




InvalidArgumentException in compiled.php line 8658:
Action App\Http\Controllers\DemoController@savess not defined.

那么当用户提交表单时,您想在savess()函数中捕获POST数据吗? - James
@James 是的,完全正确。 - Ayaz Ali Shah
1个回答

2
请在routes.php文件中添加以下代码行:
Route::post("savess", "DemoController@savess");

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接