Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用存储文件夹显示循环数据的图像_Php_Laravel_Image - Fatal编程技术网

Php 如何使用存储文件夹显示循环数据的图像

Php 如何使用存储文件夹显示循环数据的图像,php,laravel,image,Php,Laravel,Image,我的图像没有显示。我正在使用存储::保存我的图像。下面是我的文件夹的外观,并且已经创建了php artisan storage:link。我已经试过这段代码了,{{asset('storage/complaint'.$c->image)},{storage\u path()./complaint'.$c->image}}和{url('/public/complaint'.$c->image)},但它似乎根本不起作用 web.php Route::get('/report-form','Comp

我的图像没有显示。我正在使用
存储::
保存我的图像。下面是我的文件夹的外观,并且已经创建了
php artisan storage:link
。我已经试过这段代码了,
{{asset('storage/complaint'.$c->image)}
{storage\u path()./complaint'.$c->image}}
{url('/public/complaint'.$c->image)}
,但它似乎根本不起作用

web.php

Route::get('/report-form','ComplaintController@create');
Route::post('/report-create','ComplaintController@store');
Route::get('/report-view','ComplaintController@index');
<?php

namespace App\Http\Controllers;

use Auth;
use Validator;
use Response;
use Carbon\Carbon;
use App\Complaint;
use Illuminate\Support\Facades\Storage;
use Illuminate\Http\Request;
use Intervention\Image\ImageManagerStatic as Image;

class ComplaintController extends Controller
{
    public function index(Request $request)
    {
        if (Auth::user()->role == 'buyer')
        {
            $complaint = Complaint::where('report_by',Auth::user()->id)->get();
            return view('buyers.complaints.index',compact('complaint'));
        }
    }

    public function create(Request $request)
    {
        return view('buyers.complaints.create');
    }

    public function store(Request $request)
    {
        if (count($request->defect_id) > 0) {
            foreach($request->defect_id as $item=>$v) {
                if (isset($request->image[$item])) {
                    $images = $request->file('image');
                    $image_resize = Image::make($images[$item]->getRealPath());
                    $image_resize->resize(900, 630);
                    $filename = $images[$item]->getClientOriginalName();

                    Storage::put($filename, $image_resize);
                    Storage::move($filename, 'public/complaint/' . $filename);
                }
                $data = array(
                    'defect_id' => $request->defect_id[$item],
                    'image' => $filename,
                    'description' => $request->description[$item],
                    'report_by' => Auth::user()->id,
                    'created_at' => Carbon::now()->toDateTimeString(),
                    'updated_at' => Carbon::now()->toDateTimeString()
                );

                Complaint::insert($data);
            }
        }
        return redirect('/report-form')->with('success','Your report is submitted!');
    }
<div class="panel">
   <form action="/report-create" method="post" enctype="multipart/form-data">
   {{ csrf_field() }}
       <table class="table table-bordered">
          <thead>
             <tr>
                 <th><center>Type of Defect</center></th>
                 <th><center>Image</center></th>
                 <th><center>Description</center></th>
                 <th><center>Action</center></th>
             </tr>
          </thead>
          <tbody>
             <tr>
                <td width="20%">
                   <select class="form-control" name="defect_id[]">
                   <option value="" selected>Choose Defect</option>
                       @foreach(App\Defect::all() as $defect)
                       <option value="{{$defect->id}}">{{$defect->name}}</option>
                       @endforeach
                </td>
                <td width="15%">
                    <input type="file" class="form-control-file" name="image[]">
                </td>
                <td width="45%">
                    <input type="text" class="form-control" name="description[]">
                </td>
                <td width="10%">
                    <button type="button" class="btn btn-info btn-sm" id="add-btn"><i class="glyphicon glyphicon-plus"></i></button>
                </td>
              </tr>
           </tbody>
        </table>
     <center><button type="submit" class="btn btn-primary">Submit</button></center>
      <br>
   </form>
</div>
<div class="panel-heading">
   <h3 class="panel-title"><strong>List of Report</strong></h3>
</div>
<div class="panel-body">
   <table class="table table-hover">
       <thead>
          <tr>
             <th>Defect Name</th>
             <th>Description</th>
             <th>Image</th>
          </tr>
       </thead>
       @foreach($complaint as $c)
           <tr class="">
                <td>{{$c->defect->name}}</td>
                <td>{{$c->description}}</td>
                <td><img src="{{ asset('storage/complaint' . $c->image)}}" class="" alt="{{$c->image}}"></td>
            </tr>
        @endforeach
   </table>
</div>
ComplaintController.php

Route::get('/report-form','ComplaintController@create');
Route::post('/report-create','ComplaintController@store');
Route::get('/report-view','ComplaintController@index');
<?php

namespace App\Http\Controllers;

use Auth;
use Validator;
use Response;
use Carbon\Carbon;
use App\Complaint;
use Illuminate\Support\Facades\Storage;
use Illuminate\Http\Request;
use Intervention\Image\ImageManagerStatic as Image;

class ComplaintController extends Controller
{
    public function index(Request $request)
    {
        if (Auth::user()->role == 'buyer')
        {
            $complaint = Complaint::where('report_by',Auth::user()->id)->get();
            return view('buyers.complaints.index',compact('complaint'));
        }
    }

    public function create(Request $request)
    {
        return view('buyers.complaints.create');
    }

    public function store(Request $request)
    {
        if (count($request->defect_id) > 0) {
            foreach($request->defect_id as $item=>$v) {
                if (isset($request->image[$item])) {
                    $images = $request->file('image');
                    $image_resize = Image::make($images[$item]->getRealPath());
                    $image_resize->resize(900, 630);
                    $filename = $images[$item]->getClientOriginalName();

                    Storage::put($filename, $image_resize);
                    Storage::move($filename, 'public/complaint/' . $filename);
                }
                $data = array(
                    'defect_id' => $request->defect_id[$item],
                    'image' => $filename,
                    'description' => $request->description[$item],
                    'report_by' => Auth::user()->id,
                    'created_at' => Carbon::now()->toDateTimeString(),
                    'updated_at' => Carbon::now()->toDateTimeString()
                );

                Complaint::insert($data);
            }
        }
        return redirect('/report-form')->with('success','Your report is submitted!');
    }
<div class="panel">
   <form action="/report-create" method="post" enctype="multipart/form-data">
   {{ csrf_field() }}
       <table class="table table-bordered">
          <thead>
             <tr>
                 <th><center>Type of Defect</center></th>
                 <th><center>Image</center></th>
                 <th><center>Description</center></th>
                 <th><center>Action</center></th>
             </tr>
          </thead>
          <tbody>
             <tr>
                <td width="20%">
                   <select class="form-control" name="defect_id[]">
                   <option value="" selected>Choose Defect</option>
                       @foreach(App\Defect::all() as $defect)
                       <option value="{{$defect->id}}">{{$defect->name}}</option>
                       @endforeach
                </td>
                <td width="15%">
                    <input type="file" class="form-control-file" name="image[]">
                </td>
                <td width="45%">
                    <input type="text" class="form-control" name="description[]">
                </td>
                <td width="10%">
                    <button type="button" class="btn btn-info btn-sm" id="add-btn"><i class="glyphicon glyphicon-plus"></i></button>
                </td>
              </tr>
           </tbody>
        </table>
     <center><button type="submit" class="btn btn-primary">Submit</button></center>
      <br>
   </form>
</div>
<div class="panel-heading">
   <h3 class="panel-title"><strong>List of Report</strong></h3>
</div>
<div class="panel-body">
   <table class="table table-hover">
       <thead>
          <tr>
             <th>Defect Name</th>
             <th>Description</th>
             <th>Image</th>
          </tr>
       </thead>
       @foreach($complaint as $c)
           <tr class="">
                <td>{{$c->defect->name}}</td>
                <td>{{$c->description}}</td>
                <td><img src="{{ asset('storage/complaint' . $c->image)}}" class="" alt="{{$c->image}}"></td>
            </tr>
        @endforeach
   </table>
</div>
使用
存储::url()
ref链接

image)}“class=”“alt=“{{{$c->image}}>
注意:确保
应用程序的URL=http://exmaplet.test
这已设置


我认为你是通过SO创建了你的洞项目。?图像仍然没有显示
$c->image
?以及你得到的url。?是
应用程序的url=http://exmaplet.test
in.env文件?如果是,我的是
APP\u URL=http://localhost
是,它是正确的,生成的url是什么?我当前的刀片页面url是
http://localhost:8000/report-查看
这就是你的意思吗?