I am using Laravel and I have a Booking model that has a one to many relationship with a Service. So a booking can have many services.
I have set up all the relationships in the models and its working fine.
In my bookings create view file I have a panel where I want to allow users to dynamically add services.
{{ Form::open(array('url' => 'bookings')) }}
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">Services</h3></div>
<div class="panel-body" id="newServices">
<a href="#" id="addService" class="btn btn-default pull-right">Add Service</a>
</div>
</div>
{{ Form::submit('Create Booking', array('class' => 'btn btn-primary btn-vostra')) }}
{{ Form::close() }}
I have a template view file bookings.service which has some input elements:
@extends('layouts.app')
@section('content')
<div class="form-group">
{{ Form::label('customer_name', 'Customer Name') }}
{{ Form::text('customer_name', Input::old('customer_name'), array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('customer_address_line_1', 'Address Line 1') }}
{{ Form::text('customer_address_line_1', Input::old('customer_address_line_1'), array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('customer_address_line_2', 'Address Line 2') }}
{{ Form::text('customer_address_line_2', Input::old('customer_address_line_2'), array('class' => 'form-control')) }}
</div>
@endsection
My question is how do I dynamically add the services view template file into the bookings view file?
Here is what I have so far but its incomplete:
$('#addService').click(function(e) {
e.preventDefault();
var html = {};
$('#newServices').append(html);
});