如何在刀片Laravel中打印json值

时间:2020-05-15 04:56:43

标签: php laravel

我在此create函数中以db json格式发送数据。

public function create(Request $request)
  {

    $posts = new Post();
    $posts->user_id = $request->id;
    $posts->title = $request->title;
    $posts->description = $request->description;
    $tags = explode(",", $request->labels);
    $encode = json_encode($tags);
    $posts->tags = $encode;
    $posts->save();
      return redirect()->back()->with('message' , 'post created!!!!!');

  }

在此getdata函数中,从db获取数据

 public function getdata()
  {
      $posts = Post::all();
      return view('allposts',compact('posts'));
  }

现在我在刀片文件中打印数据,但标签字段中的标签值为null。 如何打印json值?

@foreach($posts as $post)
<tr>
    <td>{{$post->title}}</td>
    <td>{{$post->description}}</td>
    <td>{{$post->tags}}</td>
    <td>
        <a href="{{url('edit_post',$post->id)}}"> <button type="button" class="btn btn-primary">update</button></a>
        <a href="{{route('delete_post',$post->id)}}"><button type="button" class="btn btn-danger" >delete</button></a>
    </td>

</tr>
@endforeach

0 个答案:

没有答案