0

I have a section on the home page of my site that contains a form called @section('registration-form'). I am unable to create a separate blade file like register.blade.php and then @yield it into the home page because the form yields after the page loads, messing up my javascript. Either way, I prefer to create a route that points directly to the form section of my page, not the entire page.

The purpose of doing this is to create a custom form, which needs a route from routes/web.php.

I'm using Laravel 5.4.

Is it possible to create a Route::get() that grabs the form @section('registration-form') only?

THE CODE:

home.blade.php

<!--- content from the home page exists here --->

<!--- form ---->

@section('registration-form')

<div class="col-lg-12">
 <form  method="POST" action="{{ `Syntax for GET request?` }}">
 {{ csrf_field() }}

 <div class="form-group" id="fname">
  <label for="name">First Name:</label>
  <input name="fname">
 </div>

 <div class="form-group" id="email">
  <label for="email">Email address:</label>
  <input id="email" type="email" name="email" value="" required>
 </div>

 <div class="form-group" id="password">
  <label for="pwd">Password:</label>
  <input id="password" type="password" name="password" required>
 </div>
 <!---- more form questions ---->

@stop 
<!--- more content from home page exists here --->

Routes/web.php

Route::get( `HOW DO I POINT TO @section('registration-form')??` )
bella
  • 43
  • 5
  • Not sure exactly what you're after, but you can `@include()` other templates/views inside blade: https://laravel.com/docs/5.4/blade#including-sub-views – brombeer Jan 16 '20 at 16:28
  • I added more details to better explain what I'm doing. Thx! – bella Jan 16 '20 at 17:28

1 Answers1

0

You should be able to put this in your routes file to return the specific Blade view:

Route::get('/whatever-you-want', function () {
    return view('registration-form', ['data' => 'data']);
});
Caleb Anthony
  • 1,105
  • 9
  • 19
  • The javascript needs to load before @section('registration-form') so it doesn't work. I also need to create a controller for this. I made a new question that you may be able to answer: [How To Load Javascript Before @Section - Laravel 5.4](https://stackoverflow.com/questions/59776781/laravel-5-4-how-to-make-javascript-load-before-section-yields). Thanks for your input – bella Jan 16 '20 at 19:49