dongluzhi5208 2019-07-17 09:14
浏览 76

我可以在post方法表单中从数据库中获取数据吗?

I have duplicate databases and I want to fetch data from the secondary database, inside my Register form which has POST method.

I tried what I can do still stuck on it few days.

This is my register.blade where I want to fetch data :

{{ csrf_field() }}
@if($getTypes->count())
@foreach($getTypes as $getType)
  <option value="{{$getType->nameMn}}">
    {{$getType->nameMn}}
  </option>
@endforeach
@endif

Here is the controller :

public function getTypes(){
  $db = DB::connection('mysql2');
  $getTypes = $db->table('merchant_types')->get();

  return view('auth/register', ['getTypes'=>$getTypes]);
}
Route::post('register', 'MerchantController@getTypes');

And here goes the Route, I've tried post & get everything.

On my view blade this error is showing :

Undefined variable: getTypes"

  • 写回答

1条回答 默认 最新

  • dongtuwu8548 2019-07-17 09:48
    关注

    You should use compact('getTypes') instead of ['getTypes'=>$getTypes], change Route::post to Route::get and then open it in browser, dd($getTypes) in view to see which type of object. I can not see what wrong.

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!