我已经创建了 laravel 包,并且有一个视图 test.blade.php 显示基本表单,但是在该表单内,尝试使用 route('contact') 时,它向我显示一条错误消息路线 [联系人] 未定义。我的路由文件 web.php 在包文件夹中<?php// matrixhive\testpackage\src\routes\web.phpRoute::get('contact', function(){ return view('testpackage::test');});Route::post('contact', function(){ echo "thanks for submission of form";});?>我在侧包中的视图文件<!DOCTYPE html><html><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script> <title>Contact Us</title></head> <body> <div style="width: 500px; margin: 0 auto; margin-top: 90px;"> @if(session('status')) <div class="alert alert-success"> {{ session('status') }} </div> @endif <h3>Contact Us</h3> <form action="{{route('contact')}}" method="POST"> @csrf <div class="form-group"> <label for="exampleFormControlInput1">Your name</label> <input type="text" class="form-control" name="name" id="exampleFormControlInput" placeholder="John Doe"> </div> <div class="form-group"> <label for="exampleFormControlInput1">Email address</label> <input type="email" class="form-control" name="email" id="exampleFormControlInput1" placeholder="name@example.com"> </div> <div class="form-group"> <label for="exampleFormControlTextarea1">Enter Your Message</label> <textarea class="form-control"name="message" id="exampleFormControlTextarea1" rows="3"></textarea> </div>
2 回答
ABOUTYOU
TA贡献1812条经验 获得超5个赞
您需要使用name()方法为路由设置名称,例如
Route::post('contact', function(){ echo "thanks for submission of form"; })->name('contact');
胡说叔叔
TA贡献1804条经验 获得超8个赞
尝试这个
通过名称直接调用路由
<?php
Route::get('contact', function(){
return view('testpackage::test');
})->name('contact');
Route::post('contact', function(){
echo "thanks for submission of form";
})->name('contact');
?>
- 2 回答
- 0 关注
- 107 浏览
添加回答
举报
0/150
提交
取消