亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 laravel 包時沒有定義路由

使用 laravel 包時沒有定義路由

PHP
弒天下 2022-07-09 16:16:24
我已經創建了 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="[email protected]">          </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');


查看完整回答
反對 回復 2022-07-09
?
胡說叔叔

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');


?>


查看完整回答
反對 回復 2022-07-09
  • 2 回答
  • 0 關注
  • 131 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號