php - 路由资源未定义 laravel 5.3

标签 php laravel laravel-5.3

我正在尝试在 Laravel 5.3 中插入​​数据,我是 Laravel 的新手,我正在尝试使用资源路由系统。当我加载我的页面时,我得到 -

InvalidArgumentException in UrlGenerator.php line 314:
Route [/admin/register-account.store] not defined.

路线

Route::group(['middleware' => 'auth'], function() {
   //Applicaion home
   Route::get('/home', 'HomeController@index');

   //Admin routes
   Route::get('/admin/home', 'AdminController@index');

   //Register Account Routes
   Route::resource('/admin/register-account', 'RegAccController');

});

表格

<form action="{{ route('/admin/register-account.store') }}" type="post">
        <input type="text" placeholder="Account name" name="acc_name" />
        <input type="text" placeholder="Account location" name="acc_location" />
        <input type="text" placeholder="Account website" name="acc_website" />

        <input type="hidden" name="_token" value="{{ csrf_token() }}" />
        <button type="submit" class="primary-btn">Register Account</button>
</form>

Controller

public function store(Request $request)
{
  $this->validate($request, [
     'acc_name' => 'required',
     'acc_location' => 'required',
     'acc_website' => 'required',
  ]);

  $regAcc = new Account;
  $regAcc->name = $request->name;
  $regAcc->website = $request->acc_location;
  $regAcc->location = $request->acc_website;
  $regAcc->save();

  return view('admin.reg-acc');
}

我认为我的问题是我定义表单操作名称的地方,但是我已经尝试了多种组合,但似乎无法再出现其他错误。

最佳答案

当您使用 route() 时助手,你应该使用 name of the resource route ,不是路径。

The route() function generates a URL for the given named route

例如:

{{ route('register-account.store') }}

您可以通过执行此命令看到实际的路由名称(参见 Name 列):

php artisan route:list

关于php - 路由资源未定义 laravel 5.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41525375/

相关文章:

javascript - 使用 JQuery 分页,PHP 不起作用

php - 使用多个查询连接 mysql

php - Laravel Cookie 未通过 Javascript 显示

php - 使用登录的 Laravel 子域重定向

php - Laravel 5.3 Amazon s3 上传问题

php - 如何在 Laravel 5.3 中的查询生成器中使用时间戳来跟踪最近 5 天注册的用户

php - 从 openid 获取用户详细信息

php - Nodejs - .node_libraries/for www-data

laravel - 如果请求输入不为空则进入数据库

php - 使用 Laravel 4 查询生成器计算时间戳