次の単純なmysqlテーブルがあります。
ID type price
テーブルは次のようになります: (userID は、ログインしているユーザー (AUTH) に割り当てられた ID です)
ID type price
1 Area 8.95
2 Areas 17.9
3 Areas 26.85
4 Areas 35.8
5 Areas 39.95
select drop-down:price の type の値に ID を使用しています。
<select name="rooms" id="Areas">
<option value="" selected="selected">0</option>
@foreach ($room as $rooms)
<option data-price="{{ $rooms->price }}" value='{{ $rooms->ID }}'>{{ $rooms->ID }}</option>
@endforeach
</select>
このようになっている理由は、js によるものです (選択に基づいて価格情報を更新します)。
情報がデータベースに保存されると、値が引き出されます。この場合は ID です。
保存されるテーブルの形式
ID USERID service price
149 1 1
150 1 2
151 1 3
152 1 4
列の価格を取得して、価格とサービスに入力すると、次のようになります。
ID USERID service price
149 1 Area 8.95
150 1 Areas 17.9
151 1 Areas 26.85
152 1 Areas 35.8
これはどのように達成できますか?JOINを使用していますか?
関連する PHP
$user = User::find(Auth::user()->id);
$input = [
Input::get('rooms'),
Input::get('pr_deodorizer'),
Input::get('pr_protectant') .
Input::get('pr_sanitizer'),
Input::get('fr_couch'),
Input::get('fr_chair'),
Input::get('fr_sectional'),
Input::get('fr_ottoman'),
Input::get('pr_tile'),
Input::get('pr_hardwood')
];
// echo '<pre>';
// var_dump($input); die;
foreach ($input as $services) {
$service = new Service();
$service->userID = $user->id;
$service->services = $services;
$service->save();
}
return Redirect::to('book/schedule');