如何在.blade页面中合并数组?

时间:2018-04-22 06:23:57

标签: php laravel

我有两个名为$ticket$answers的数组,它们被传递给视图。这是我在刀片中的代码:

@foreach($answers as $answer)
    <div class="description">{{$answer->desc}}</div>
    <div class="author">{{$answer->user->name}}</div>
@endforeach
<div class="description">{{$ticket->desc}}</div>
<div class="author">{{$ticket->user->name}}</div>

{{$answer->render()}}

当没有任何分页时,我的代码很有效。但是当{{$answer->render()}}打印时,票证将出现在所有页面中。那不是我想要的。我想只在最后一页打印它。换句话说,我想将$ticket$answers合并为最后一项($answers按降序排序)。

我该怎么做?

1 个答案:

答案 0 :(得分:1)

使用private FileContentModel getDbData(String url)throws ApiException, IOException, ConnectionException { TypeToken<FileContentModel> typeToken = new TypeToken<FileContentModel>() {}; return getData(url, getPostModel(), typeToken); } private <T> T getData(String url, PostModel postModel, TypeToken<T> typeToken) throws ApiException, IOException, ConnectionException { Response response = new CallApi<T>(Connection.getOfficeApiUrl(context)) .Post(url, postModel); if (response.code() != 200) throw new ApiException(context, response); Gson gson = new GsonBuilder() .setLenient() .create(); T obj = gson.fromJson(response.body().charStream(), typeToken.getType()); return obj; } public Response Post(String route, Object object) throws IOException { Gson gson = new Gson(); RequestBody body = RequestBody.create(MediaType.parse(MIME_JSON), gson.toJson(object)); Request request = new Request.Builder() .url(baseUrl + route) .post(body) .addHeader("Accept-Encoding", "gzip") .build(); return okHttpClient.newCall(request).execute(); } 将最后一个值添加为故障单

$loop->last