2017-10-14 24 views
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); 


    } 

で最も苦労していますどここれはこれは私が欲しいのデータでありますクライアントテーブルからpoにフェッチするクライアント名を選択すると、請求書のテーブルが表示されます。

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(); 
    }); 
+0

Laravelに同梱されているVueとAxios(ajaxリクエストを扱う)を使用することを検討してください。あなたのpopulate()関数は$クライアントを返すべきですが、それはなぜですか?クライアントを選択するとブラウザのコンソールにデータが表示されるのはこのためだと思います。 – Spacemudd

+0

私は私の質問で私がIDを取得していることを述べました、それは問題ではありません。問題は私が苦労していることです。私の請求書に入力するためのタイトルを返すロジック。ありがとう –

答えて

1

Spacemuddは、ブラウザのコンソールでデータを見ることができる後

return $client; 

$client =Client::find($request->id); 

後移入機能に欠けている。言ったように