为了账号安全,请及时绑定邮箱和手机立即绑定

如何将值从输入文本框传递到拉拉维尔中的另一个页面

如何将值从输入文本框传递到拉拉维尔中的另一个页面

PHP
郎朗坤 2022-09-17 21:37:24
索引控制器如下所示<?phpnamespace App\Http\Controllers;use Illuminate\Http\Request;class IndexController extends Controller{    public function index()    {        return view('welcome');    }    public function about()    {        return view('about');    }  public function contact()  {    return view('contact');  }  public function thanks(Request $request)  {    $request->validate(['firstname' => ['required', 'alpha_num']]);    return view('thanks');  }}接触刀片.php在下面@extends('welcome')@section('content')          <div>            <h2>Contact Page</h2>            <form method="post" action="{{route("thanks")}}">              @csrf<input type="text" name="firstname"/>              <input type="submit"/>            </form>            @if ($errors->any())            <div class="alert alert-danger">              <ul>                @foreach ($errors->all() as $error)                <li>{{ $error }}</li>                    @endforeach              </ul>            </div>                @endif                  </div>  @endsection谢谢刀片.php@extends('welcome')@section('content')<div>  <h2>Thanks</h2>Thank you {{ $firstname }}</div>@endsection欢迎刀片.php  <div class="flex-center position-ref full-height">            <div class="content">                <div class="title m-b-md">                    app                </div>                <div class="links">                    <a href="{{ route('about')  }}">About</a>                    <a href="{{ route('contact')  }}">contact</a>                </div>                <h1>{{$firstname}}</h1>                <div>                    @yield('content')                </div>            </div>        </div>当我在 welcome.blade 中单击“联系人”时.php它会将我带到“联系人”页面,其中文本框是按压的 。输入的值应显示在“谢谢”.php中。我需要在文本框中输入的值显示在感谢.blade中.php当我单击提交时。提前致谢
查看完整描述

1 回答

?
largeQ

TA贡献2039条经验 获得超8个赞

数据需要显式传递到视图。出于希望显而易见的原因,它不能作为变量在全球范围内访问。

例如

return view('thanks', ['firstname' => 'Your First Name']);


查看完整回答
反对 回复 2022-09-17
  • 1 回答
  • 0 关注
  • 140 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号