当我单击按钮时,我在此集合实例上获得了消息属性[id]

发布于 2025-02-09 23:56:48 字数 3061 浏览 1 评论 0原文

在此集合实例上不存在。

我遇到了“属性[id ] php

@extends('layout.admin')

@push('css')

@section('content')
  <body>
    <h1 class="text-center mb-4" >Data Rekap</h1>
    <div class="container mb-5">
        <h2>Dokumentasi  Customer : <span class="text-primary">{{$data->customer}}</span> </h2>
          <a href="/rekap" class="btn btn-primary">Kembali</a>
          <button href="/download_image/{{ $images->id }}" class="btn btn-primary center">DOWNLOAD</button>
          @foreach ($images as $image)
          <div class="row mt-4">
                <div class="col-md-3">
                  <div class="card" style="max-width: 50rem;">
                    <div class="card-body">
                      <img src="{{asset('images_rekap/'.$image->image)}}" class="card-img-top mb-2">
                      <a href="/deleteimagerekap/{{ $image->id }}" class="btn btn-primary center">HAPUS</a>
                    </div>
                  </div>
                </div>
            @endforeach
          </div>
        </div>
    </div>

    @push('script')
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-fQybjgWLrvvRgtW6bFlB7jaZrFsaBXjsOMm/tB9LTS58ONXgqbR9W8oWht/amnpF" crossorigin="anonymous"></script>
  @endpush
  </body>
@endsection

和此rekapController

public function download_image($id)
{

$images = image_rekap::where('rekap_id',$id)->get();

$images = [];
foreach ($images as $i => $image) {
    $images[$image->id] = public_path(). $image->image;

}

// dd($images);

$data       = rekap::find($id);
$folderName = $data->id.'-'.str_replace(' ', '-',$data->customer);
$zip        = new ZipArchive;
$zipFile    = public_path().'/image_rekap/'.$folderName.'/'.$folderName.'.zip';

if ($zip->open($zipFile, ZipArchive::CREATE) === TRUE)
{

    //add files into a zip
    foreach ($images as $key => $value) {

        //replace word "full" with $portfolioImage->id
        $relativeNameInZipFile = str_replace('full',$key,basename($value));
        $zip->addFile($value, $relativeNameInZipFile);
    }

    $zip->close();
}

return response()->download($zipFile);

,这是我的路由

Route::get('/download_image/{id}',[RekapController::class, 'download_image'])->name('download_image')->middleware('auth');

如何修复它?

I got error "Property [id] does not exist on this collection instance. (View: D:\Kerja\cst-rekap\resources\views\image_rekap.blade.php)"\

This my bladeimage_rekap.blade.php

@extends('layout.admin')

@push('css')

@section('content')
  <body>
    <h1 class="text-center mb-4" >Data Rekap</h1>
    <div class="container mb-5">
        <h2>Dokumentasi  Customer : <span class="text-primary">{{$data->customer}}</span> </h2>
          <a href="/rekap" class="btn btn-primary">Kembali</a>
          <button href="/download_image/{{ $images->id }}" class="btn btn-primary center">DOWNLOAD</button>
          @foreach ($images as $image)
          <div class="row mt-4">
                <div class="col-md-3">
                  <div class="card" style="max-width: 50rem;">
                    <div class="card-body">
                      <img src="{{asset('images_rekap/'.$image->image)}}" class="card-img-top mb-2">
                      <a href="/deleteimagerekap/{{ $image->id }}" class="btn btn-primary center">HAPUS</a>
                    </div>
                  </div>
                </div>
            @endforeach
          </div>
        </div>
    </div>

    @push('script')
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-fQybjgWLrvvRgtW6bFlB7jaZrFsaBXjsOMm/tB9LTS58ONXgqbR9W8oWht/amnpF" crossorigin="anonymous"></script>
  @endpush
  </body>
@endsection

and this RekapController

public function download_image($id)
{

$images = image_rekap::where('rekap_id',$id)->get();

$images = [];
foreach ($images as $i => $image) {
    $images[$image->id] = public_path(). $image->image;

}

// dd($images);

$data       = rekap::find($id);
$folderName = $data->id.'-'.str_replace(' ', '-',$data->customer);
$zip        = new ZipArchive;
$zipFile    = public_path().'/image_rekap/'.$folderName.'/'.$folderName.'.zip';

if ($zip->open($zipFile, ZipArchive::CREATE) === TRUE)
{

    //add files into a zip
    foreach ($images as $key => $value) {

        //replace word "full" with $portfolioImage->id
        $relativeNameInZipFile = str_replace('full',$key,basename($value));
        $zip->addFile($value, $relativeNameInZipFile);
    }

    $zip->close();
}

return response()->download($zipFile);

and this my route

Route::get('/download_image/{id}',[RekapController::class, 'download_image'])->name('download_image')->middleware('auth');

How to fix it ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月隐月明月朦胧 2025-02-16 23:56:48

错误可能来自此行,

<button href="/download_image/{{ $images->id }}" class="btn btn-primary center">DOWNLOAD</button>

您要尝试访问$ images-&gt; id$ images没有id property属性。很明显为什么。尝试删除此代码,观察错误消失。或将其放在foreach循环中

          @foreach ($images as $image)
          <button href="/download_image/{{ $image->id }}" class="btn btn-primary center">DOWNLOAD</button>
          <div class="row mt-4">
                <div class="col-md-3">
                  <div class="card" style="max-width: 50rem;">
                    <div class="card-body">
                      <img src="{{asset('images_rekap/'.$image->image)}}" class="card-img-top mb-2">
                      <a href="/deleteimagerekap/{{ $image->id }}" class="btn btn-primary center">HAPUS</a>
                    </div>
                  </div>
                </div>
           @endforeach

The error is probably coming from this line

<button href="/download_image/{{ $images->id }}" class="btn btn-primary center">DOWNLOAD</button>

You are trying to access $imageS->id and $images doesn't have an id property. It's obvious WHY. Try removing this line of code and watch the error disappear. Or put it in the foreach loop like so

          @foreach ($images as $image)
          <button href="/download_image/{{ $image->id }}" class="btn btn-primary center">DOWNLOAD</button>
          <div class="row mt-4">
                <div class="col-md-3">
                  <div class="card" style="max-width: 50rem;">
                    <div class="card-body">
                      <img src="{{asset('images_rekap/'.$image->image)}}" class="card-img-top mb-2">
                      <a href="/deleteimagerekap/{{ $image->id }}" class="btn btn-primary center">HAPUS</a>
                    </div>
                  </div>
                </div>
           @endforeach
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文