【问题标题】:Route with post action in laravel在 laravel 中带有 post 操作的路由
【发布时间】:2019-03-05 02:31:18
【问题描述】:

我是 laravel 的新手。我在 laravel 中创建了一个项目。 我有两条路线:

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

Route::post('/task' , function(Request $request)
{
 $validator = Validator::make($request->all(),[
  'name' => 'required|max:255',
 ]);

 if ($validator->fails())
 {
   return redirect('/')
          ->withInput()
          ->withErrors($validator);
 }

 $task = new Task;
 $task->name = $request->name;
 $task->save;

 return redirect('/');
});

我在 URL“http://localhost:1234/quickstart/public/”的页面中。

当我在我的页面中提交时,应该运行 Route "Route::post('/task' , function(Request $request)"。

运行 taht 后,我​​转到页面“http://localhost:1234/task”而不是页面“http://localhost:1234/quickstart/public/task”并得到错误“找不到对象!”

【问题讨论】:

  • 欢迎来到 Stackoverflow。由于您还没有找到任何答案,它可能会帮助您编辑您的问题。解释您正在尝试做什么以及您如何尝试解决问题。如需指导,请阅读how to ask questionshow to create a minimal example

标签: php laravel-5.2


【解决方案1】:

欢迎使用 Laravel

在 laravel 中,我们不使用这种类型的路由。不要直接访问公用文件夹。

  1. 您可以使用php artisan serve 进行本地开发。
  2. 您也可以使用虚拟主机。

【讨论】:

    猜你喜欢
    • 2013-09-05
    • 2019-06-27
    • 2017-12-07
    • 2020-01-01
    • 2021-06-06
    • 2014-04-28
    • 2021-02-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多