我已经创建了laravel软件包,并在其中显示了基本表单的一个视图test.blade.php,但是当尝试使用route('contact')时,在该表单中却显示了一条错误消息
未定义路线[联系人]。
我的路由文件web.php位于软件包文件夹中
<?php
// matrixhive\testpackage\src\routes\web.php
Route::get('contact', function(){
return view('testpackage::test');
});
Route::post('contact', function(){
echo "thanks for submission of form";
});
?>
侧面包装中的我的查看文件
<!DOCTYPE html>
<html lang="en">
<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>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</body>
</html>
我正在从here
学习laravel软件包开发答案 0 :(得分:1)
尝试一下
通过名称直接拨打电话
<?php
Route::get('contact', function(){
return view('testpackage::test');
})->name('contact');
Route::post('contact', function(){
echo "thanks for submission of form";
})->name('contact');
?>
答案 1 :(得分:1)
您需要使用类似
的 name()方法设置路线的名称
Route::post('contact', function(){ echo "thanks for submission of form"; })->name('contact');