前提・実現したいこと
laravel Form::select()に変数は指定できない?
セレクトボックスの値をDBっから持ってきた配列にしたい。
ここに質問の内容を詳しく書いてください。
{{Form::select('affiliate_id', $affiliate_list ,null , array('id' => 'affiliate_id'))}}
controllerには
$affiliate_listにDBから店舗情報を持ってきています
発生している問題・エラーメッセージ
Undefined variable: affiliate_list (View: /Users/tns/project/hmpay_admin/resources/views/list/user.blade.php)
Previous exceptions
エラーメッセージ
該当のソースコード
user.blade.php
<body> <html> <main style="height:699px;"> <div class="scroll"> <section class="mobile_auth_search search_form"> <div class="tit head_area"> <section class="mobile_auth_search search_form"> <input type="hidden" value='0' class="search_display"> <div class="tit head_area"> <h3>認証番号一覧</h3> </div> {{Form::open(array('action' => 'MobilePhoneAuthController@search', 'method' => 'POST', 'id' => 'mobile_auth_search_form'))}} {{Form::hidden('csv', 0, array('id' => 'csv'))}} <div class="form-area cf"> <div class="form-part col2"> <p class="lbl">加盟店名</p> <p class="inpt"> {{Form::select('affiliate_id',$affiliate_list , null , array('id' => 'affiliate_id'))}} </p> <div class="btn-area"> {{Form::button('search_btn', '検索', array('type' => 'button', 'class' => 'btn', 'id' => 'search'))}} {{Form::button('reset', 'リセット', array('type' => 'button', 'class' => 'btn', 'id' => 'reset'))}} </div> {{Form::close()}} </div> </section> </div> </main> </html> </body>
MobilePhoneAuthController.php
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\MobilePhoneAuth; use App\M_Affiliate; class MobilePhoneAuthController extends Controller { public function search(Request $request){ $affiliate_list = M_Affiliate::all('shop_name'); } }
M_Affiliate.php
<?php namespace App; use Illuminate\Database\Eloquent\Model; class M_Affiliate extends Model { protected $table = "m_affiliate"; protected $fillable = [ 'affiliate_id','shop_name','shop_name_yagou','login_url_name', 'service_name', 'callcenter_n','callcenter_tel','operation_hours','bank_f','newitem_f','charge_scheme_a_init','charge_scheme_b_init','charge_margin_koza','charge_margin_card','agent_margin','shop_id_card','shop_pass_card', 'site_id_card','site_pass_card','sms_username', 'sms_password', 'logo_file_path','service_video_url','discharge_sounds_file_path','virtual_bank_branche_id','arbitrarily_coupon_flg','arbitrarily_sms_flg','login_line_flg','contactless_payment_flg','first_customer_confirm_flg','customize_css_flg','create_user','create_d','update_d','update_user','del_flg','discharge_sounds_file_path2' ]; }
migration
<?php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; class CreateMAffiliateTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('m_affiliate', function(Blueprint $table) { $table->string('affiliate_id', 4)->primary(); $table->string('shop_name', 200)->nullable(); $table->string('shop_name_yagou')->nullable()->comment('屋号'); $table->string('login_url_name', 200)->nullable()->comment('ログインURLにセットする名称'); $table->string('service_name', 200)->nullable()->comment('サービス名'); $table->string('callcenter_n', 200)->nullable(); $table->string('callcenter_tel', 13)->nullable(); $table->string('operation_hours', 200)->nullable(); $table->integer('bank_flag')->nullable(); $table->integer('newitem_flag')->nullable(); $table->boolean('charge_scheme_a_initial')->nullable(); $table->boolean('charge_scheme_b_initial')->nullable(); $table->integer('charge_margin_koza')->comment('口座振替手数料'); $table->integer('charge_margin_card')->comment('クレジットカード手数料'); $table->integer('agent_margin')->default(0)->comment('収納代行手数料'); $table->string('shop_id_card', 20)->nullable(); $table->string('shop_pass_card', 100)->nullable(); $table->string('site_id_card', 20)->nullable(); $table->string('site_pass_card', 100)->nullable(); $table->string('sms_username', 100)->nullable()->comment('SMSアカウント'); $table->string('sms_password', 100)->nullable()->comment('SMSパスワード'); $table->string('logo_file_path')->nullable()->comment('ロゴ・ファイル・path'); $table->string('service_video_url', 510)->nullable()->comment('サービス紹介動画URL'); $table->string('discharge_sounds_file_path')->nullable()->comment('音声・ファイル・path'); $table->string('virtual_bank_branche_id')->nullable()->comment('仮想銀行支店マスタID'); $table->boolean('arbitrarily_coupon_flg')->nullable()->comment('クーポン任意付与設定フラグ'); $table->boolean('arbitrarily_sms_flg')->nullable()->comment('SMS任意付与設定フラグ'); $table->boolean('login_line_flg')->nullable()->comment('LINE連携フラグ'); $table->boolean('contactless_payment_flg')->nullable()->comment('非接触決済フラグ'); $table->boolean('first_customer_confirm_flg')->nullable()->default(0)->comment('一見顧客確認画面フラグ'); $table->boolean('customize_css_flg')->nullable()->comment('オリジナル会員ページ'); $table->string('create_user', 80)->nullable(); $table->dateTime('create_date')->nullable(); $table->dateTime('update_date')->nullable(); $table->string('update_user', 80)->nullable(); $table->boolean('del_flg', 1)->nullable(); $table->string('discharge_sounds_file_path2')->nullable()->comment('音声・ファイル・path'); }); }
試したこと
コントローラーに変数を指定
補足情報(FW/ツールのバージョンなど)
laravel5.8
ここにより詳細な情報を記載してください。