控制器类未找到laravel 5.1

时间:2016-12-01 12:17:05

标签: php laravel laravel-5.1

我是laravel的新手,我试图将值从视图发布到控制器。但是,由于我得到错误的说法,我无法通过 提交表单时FatalErrorException in routes.php line 26: Class 'registration' not found

routes.php文件

Route::get('/', function () {
    return view('welcome');
});

Route::get('/register', function(){
return view('register');
});

Route::post('/register_action', function()
{
     $values = registration::store();
});

控制器

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\model\registration as register_model

class registration extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store()
    {
        echo 'hello';
        register_model::saveFormData();
    }
}

查看

<html>
<head>
    <meta charset="UTF-8">
    <title>Registration</title>
</head>
<body>
    {!! Form::open(array('url' => 'register_action')) !!}
        <p>Name : {!! Form::text('name') !!}</p>
        <p>Email : {!! Form::text('email') !!}</p>
        <p>Password : {!! Form::password('password') !!}</p>
        <p>Confirm Password : {!! Form::password('cpassword') !!}</p>
        <p>{!! Form::submit('Submit') !!}</p>
    {!! Form::close() !!}
</body>
</html>

请帮我解决问题并获取控制器中的帖子值。谢谢

3 个答案:

答案 0 :(得分:3)

你不能使用这样的控制器:

$values = registration::store();

使用需要更改路线。

Route::post('/register_action', 'registration@store');

答案 1 :(得分:1)

如果你需要在路由中调用控制器方法(这是一个坏主意)你可以添加一个使用语句

use App\Http\Controllers\registration;

但由于您静态调用非静态方法,它仍然会给您一个错误,因此您最好的选择是@Alexey Mezenin answer

答案 2 :(得分:0)

路线应如下所示:

Route::post('/register_action', 'registration@store');

https://laravel.com/docs/5.3/routing