<?php
namespace 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');
}
}
@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
@extends('welcome')
@section('content')
<div>
<h2>Thanks</h2>Thank you {{ $firstname }}
</div>
@endsection
<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>
<?php
Route::get('/', 'IndexController@index');
Route::get('/about', 'IndexController@about')->name('about');
Route::get('/contact','IndexController@contact')->name('contact');
Route::post('/contact','IndexController@thanks')->name('thanks');
welcome.blade.php에서 연락처를 클릭하면 텍스트 상자가 눌러 진 연락처 페이지로 이동합니다. 입력 한 값은 thankyou.blade.php에 나타나야합니다. 제출을 클릭 할 때 thanks.blade.php에 표시되도록 텍스트 상자에 입력 한 값이 필요합니다. 미리 감사드립니다
데이터는 명시 적으로 뷰에 전달되어야합니다. 분명한 이유로 변수로 전역 적으로 액세스 할 수 없습니다.
예
return view('thanks', ['firstname' => 'Your First Name']);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다