1

The indexcontroller is shown below

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


}

contact.blade.php is below

@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

Thanks.blade.php

@extends('welcome')
@section('content')
<div>
  <h2>Thanks</h2>Thank you {{ $firstname }}
</div>
@endsection

welcome.blade.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>

web.php

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

When I click on contact in welcome.blade.php it takes me to contact page where the textbox is pressent . The value entered should appear in thankyou.blade.php. I need the value entered in the textbox to be shown in thanks.blade.php when I click on submit. Thanks in Advance

1
  • what the current problem? Commented Feb 13, 2020 at 1:38

1 Answer 1

1

Data needs to be passed to a view explicitly. For hopefully obvious reasons, it isn't globally accessible as a variable.

E.g.

return view('thanks', ['firstname' => 'Your First Name']);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.