Laravel: How do I parse this json data in view blade?

后端 未结 8 1258
耶瑟儿~
耶瑟儿~ 2020-11-29 03:11

Currently this is my view

{{ $leads }}

And this is the output

{\"error\":false,\"member\":[{\"id\":\"1\",\"firstName\":\"fi         


        
相关标签:
8条回答
  • 2020-11-29 03:47

    For such case, you can do like this

    @foreach (json_decode($leads->member) as $member)
         {{ $genre }}
    @endforeach
    
    0 讨论(0)
  • 2020-11-29 03:47

    If your data is coming from a model you can do:

    App\Http\Controller\SomeController

    public function index(MyModel $model)
    {
        return view('index', [
            'data' => $model->all()->toJson(),
        ]);
    }
    

    index.blade.php

    @push('footer-scripts')
      <script>
        (function(global){
          var data = {!! $data !!};
          console.log(data);
          // [{..}]
        })(window);
      </script>
    @endpush
    
    0 讨论(0)
提交回复
热议问题