Laravelで商品登録画面を作っています。
商品に店名と支店名を関連付けたいのですが、フォームに正しく表示ができません。
*以下のサンプルだとshop_idは表示できるのですが、shop_nameとshop_branch_nameが表示できない。
controller側で、shop_name+shop_branch_nameを設定したいのですが、
どのようにしたらよいかご教示いただけませんでしょうか。
よろしくお願いいたします。
DB
inventory (id ,,, shop_branch_id)
shop_branch (id ,shop_branch_name, shop_id)
shop(id ,shop_name)
関連付け
inventory->shop_branch->shop
Controller
php
1 public function create() 2 { 3 4 $shops = ShopBranch::lists('shop_id','id')->all(); 5 $payment = Payment::lists('name','id')->all(); 6 $condition = Condition::lists('name','id')->all(); 7 $sale_place = SalePlace::lists('name','id')->all(); 8 9 return view('admin.inventory.create',compact('shops','payment', 'condition','sale_place')); 10 11 }
View
php
1 {!! Form::open(['method'=>'POST','action'=>'AdminInventoriesController@store','files'=>true]) !!} 2 3 4 5 <div class="form-group"> 6 {!! Form::label('shop_branch_id','Shop:') !!} 7 {!! Form::select('shop_branch_id',[''=>'Choose Shops'] + $shops,null,['class'=>'form-control']) !!} 8 </div> 9 10 11{!! Form::close() !!}
Inventoryモデル
php
1 public function shop_branch() { 2 return $this->belongsTo('App\ShopBranch'); 3 }
ShopBranchモデル
php
1 public function shop() { 2 return $this->belongsTo('App\Shop'); 3 }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。