我想将表单提交给usercontroller文件并调用函数invitebyemail。
当我点击提交时,它会给我一个错误,例如"哎呀,看起来出了问题。"
以下是我的文件和代码的结构。
路线档案:
Route::POST('event/inviteforevent', 'UserController@invitebyemail');
Blade.php文件
<form action="{{ route('inviteforevent') }}" method="POST">
<input type="email" class="form-control full-width" id="add-members-event-email" name="email" placeholder="Email address">
<input type="hidden" class="form-control full-width" name="eventid" value="{{ $event->id }}" >
<input type="submit" name="invite" value="submit" />
</form>
UserController文件:
public function invitebyemail(Request $request){
$event = Event::find($request->eventid);
$timelineId = $event->timeline_id;
$username = Auth::user()->username;
$timelines = Timeline::find($timelineId);
return redirect()->back()->with('message', 'Invitation send to user by email.');
}
答案 0 :(得分:1)
using Microsoft.Azure
辅助函数需要路由名称。
route()
修改强>
运行Route::post('event/inviteforevent', 'UserController@invitebyemail')->name('inviteforevent');
并在php artisan serve
访问您的服务器。您尚未设置网络根目录,并且laravel网址重写无法正常工作以及生成错误链接的http://localhost:8000
和url
方法。
答案 1 :(得分:1)
除了建议的路线更改外,您可能需要添加
{{ csrf_field() }}
之后
<form action="{{ route('inviteforevent') }}" method="POST">
在此处阅读更多内容:https://laravel.com/docs/5.4/csrf#csrf-introduction
答案 2 :(得分:0)
变化
Route::POST('event/inviteforevent', 'UserController@invitebyemail');
到
Route::POST('event/inviteforevent', 'UserController@invitebyemail')->name("inviteforevent");
答案 3 :(得分:0)
请在路线中替换此代码: -
---
swagger: "2.0"
info:
version: "1.0.0"
title: "Swagger Petstore"
description: "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification"
termsOfService: "http://swagger.io/terms/"
contact:
name: "Swagger API Team"
license:
name: "MIT"
host: "petstore.swagger.io"
basePath: "/api"
schemes:
- "http"
consumes:
- "application/json"
produces:
- "application/json"
paths:
/pets:
get:
description: "Returns all pets from the system that the user has access to"
produces:
- "application/json"
responses:
"200":
description: "A list of pets."
schema:
type: "array"
items:
$ref: "#/definitions/Pet"
definitions:
Pet:
type: "object"
required:
- "id"
- "name"
properties:
id:
type: "integer"
format: "int64"
name:
type: "string"
tag:
type: "string"
OR
Route::post('event/inviteforevent', 'UserController@invitebyemail')->name('inviteforevent');
答案 4 :(得分:0)
你必须添加{{ csrf_field() }}
建议但只有一个问题?表单中的表名和ID在哪里打开?该表单如何知道要添加数据的表?
您必须在表单中添加$events
和$events->id