0
这是我的发票形式。我想根据来自数据库选项字段的选择填充标题。如何从客户数据库获取值以填充发票表单中的标题。谢谢。选择名称时填入输入
<form action="{{ route('admin.invoices.store') }}" method="post">
{{ csrf_field() }}
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label for="invoicenumber">Invoice Number</label><br>
<input class="form-control" type="text" name="invoice_no" id="number">
<span class="alert-danger" id="number-feedback"></span>
</div>
<div class="form-group">
<label for="client">Client</label><br>
<select name="client" id="client_id" class="form-control">
<option value="select">Select Client</option>
@foreach($clients as $client)
<option id="option" value="{{ $client-> id|$client->name }}">{{ $client->name }}</option>
@endforeach
</select>
</div>
<div class="form-group">
<label for="Title">Title</label><br>
<input class="form-control" type="text" name="title" id="title">
<span class="alert-danger" id="title-feedback"></span>
</div>
</div>
我的路线
Route::post('/populate', '[email protected]');
我的Ajax请求
$(document).on('change', '#client_id', function(event){
var id = $("#client_id").find(":selected").text();
$.ajax({
type: "POST",
url: '/populate',
data: {id: id, '_token':$('input[name=_token]').val()},
success: function(data) {
//$('#refresh').load(location.href + ' #refresh');
console.log(data);
}
});
});
的这是我很努力最有逻辑
public function populate(Request $request){
$client =Client::find($request->id);
}
这就是我想要的数据从客户端表中取回到宝当我选择客户名称时计费发票表。
Schema::create('clients', function (Blueprint $table) {
$table->increments('id');
$table->string('company');
$table->string('title');
$table->string('name');
$table->string('phone_number');
$table->string('email');
$table->string('address');
$table->string('state');
$table->string('city');
$table->string('country');
$table->string('code');
$table->string('info');
$table->string('image');
$table->timestamps();
});
考虑使用Laravel附带的Vue和Axios(处理ajax请求)。虽然,你的populate()函数应该返回$ client,为什么不呢?我想这就是为什么当你选择一个客户端时,你的浏览器的控制台中会显示任何数据。 – Spacemudd
我在我的问题中提到我得到了id,那不是问题所在。问题是我在挣扎。在我的发票中返回标题以填充输入的逻辑。谢谢 –