AhmedMamdouh's avatar

Problem in uploading image

I don't know why i can't get the image name from database?!

@extends('admin.layouts.app')

@section('main-content')

                             <div class="row m-t-sm m-b-xs">
                                <div class="col-md-6">
                                   <h3 class="title m-t-sm pull-left bold">الخدمات</h3>
                                </div>
                                <div class="col-lg-6">
                                  <button class="btn btn-primary btn-rounded pull-right" data-toggle="modal" data-target="#add">اضافة خدمة جديدة <i class="fa fa-plus-circle" aria-hidden="true" style="padding-right: 10px"></i></button>
                                </div>
                             </div>
                          </div>


                                                 @foreach($services as $service)

                    <div class="ibox-title  back-change">
                       <h5> {{ $service->title }}</h5>
                    </div>
                    <div class="ibox-content">
                    
                     
                   
                        <form class="form-horizontal">
                           <!--  -->
                           <div class="form-group">
                             <label class="col-md-2 control-label">الصورة</label>
                             <div class="col-md-10">
                               <div class="fileinput fileinput-new input-group" data-provides="fileinput">
                                 <span class="input-group-addon btn btn-default btn-file">
                                      <span class="fileinput-new">تحميل ملف</span>
                                       <span class="fileinput-exists">تغيير</span>
                                      <input type="file" value="{{$service->image}}" />
                                      </span>
                              <a href="#" class="input-group-addon btn btn-default fileinput-exists" data-dismiss="fileinput">حذف</a>
                              <div class="form-control" data-trigger="fileinput">
                                  <i class="glyphicon glyphicon-file fileinput-exists"></i>
                              <span class="fileinput-filename"></span>
                              </div>
                              
                            </div> 
                             </div>
                           </div>



                           <!--  -->
                            <div class="form-group"><label class="col-md-2 control-label">عنوان</label>

                                <div class="col-md-10"><input type="text" placeholder="" value="{{ $service->title }}" class="form-control"> 
                                </div>
                            </div>
                           
                            <div class="form-group"><label class="col-md-2 control-label">الموضوع </label>

                                <div class="col-md-10"><textarea type="text" placeholder=""  rows="4"   class="form-control"> {{ $service->body }}</textarea>  
                                </div>
                            </div>

                         
                         
                           
                            <div class="form-group">
                                <div class="col-lg-offset-2 col-lg-10">
                                   <button class="btn btn-primary pull-right" type="submit">حفظ التغيرات</button>
                                </div>
                            </di>
                        </form>

                   
              
                    </div>

                    @endforeach
                 </div>
              </div>
              <!--  -->
           </div>
           
< ×

اضافة خدمة جديدة

{{ csrf_field() }} الصورة اختر الصورة تغير حذف
                            </div> 
                             </div>
                           </div>
                           <!--  -->
                            <div class="form-group"><label class="col-md-2 control-label">عنوان</label>

                                <div class="col-md-10"><input type="text" placeholder="" name="title" class="form-control"> 
                                </div>
                            </div>
                           
                            <div class="form-group"><label class="col-md-2 control-label">الموضوع </label>

                                <div class="col-md-10"><textarea type="text" placeholder=""  name="body" rows="4"  class="form-control"></textarea>  
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-lg-offset-2 col-lg-10">
                                   <button class="btn btn-primary pull-right" type="submit">حفظ التغيرات</button>
                                </div>
                            </div>
                        </form>
  </div>
 
</div>
        </div>

@endsection

Another thing in this it don't accept that i'm giving it an image and return No

Controller

public function update(Request $request, Slider $slider) {

if(!($request->hasFile('image'))){

            return 'No';
        }
        else{
            return 'yes';
        }

}

@extends('admin.layouts.app')

@section('main-content')

<div class="wrapper wrapper-content animated fadeInRight">
        {{ csrf_field() }}         

        {{method_field('PATCH')}}

              <div class="row">
              <div class="col-lg-12">
                 <div class="ibox float-e-margins">
                    <div class="ibox-title  back-change">
                       <h5>الغلاف </h5>
                    </div>
                    <div class="ibox-content">
                       <div class="row">
                          <div class="col-md-6">
                             <div class="image-crop">
                                <img  src="">
                             </div>
                          </div>



                          <div class="col-md-6">
                             <div class="btn-group">
                                <label title="Upload image file" for="inputImage" class="btn btn-primary">
                                <input type="file" accept="image/*" name="image" id="inputImage" class="hide">
                                Upload new image
                                </label>
                                <!-- <label title="Donload image" id="download" class="btn btn-primary">Download</label> -->
                             </div>





                             <div class="btn-group">
                                <button class="btn btn-white" id="zoomIn" type="button">Zoom In</button>
                                <button class="btn btn-white" id="zoomOut" type="button">Zoom Out</button>
                                <button class="btn btn-white" id="rotateLeft" type="button">Rotate Left</button>
                                <button class="btn btn-white" id="rotateRight" type="button">Rotate Right</button>
                               <!--  <button class="btn btn-warning" id="setDrag" type="button">New crop</button> -->
                             </div>
                          </div>



                           <div class="form-group">
                                <div class="col-lg-offset-2 col-lg-10">
                                   <button class="btn btn-primary pull-right" type="submit"> حفظ التغيرات</button>
                                </div>
                            </div>



                       </div>
                    </div>
                 </div>
              </div>

          </div>
      </form>
  </div>




                <div class="row">
              <div class="col-lg-12">
                 <div class="ibox float-e-margins">
                    <div class="ibox-title  back-change">
                       <h5>المحتوي</h5>
                    </div>
                    <div class="ibox-content">
                    
                     
                   
                    <div class="ibox-content">
                        <form class="form-horizontal">
                           
                            <div class="form-group"><label class="col-md-2 control-label">Header</label>

                                <div class="col-md-10"><input type="text" placeholder="" name="header" value="{{ $slider->header }}" class="form-control"> 
                                </div>
                            </div>
                           
                            <div class="form-group"><label class="col-md-2 control-label">Paragraph</label>

                                <div class="col-md-10"><textarea type="text" placeholder="" rows="4"  name="paragraph"  class="form-control">{{ $slider->paragraph }}</textarea>  
                                </div>
                            </div>
                         
                         
                           
                            <div class="form-group">
                                <div class="col-lg-offset-2 col-lg-10">
                                   <button class="btn btn-primary pull-right" type="submit">حفظ التغيرات</button>
                                </div>
                            </div>
                        </form>

                    </div>
              
                    </div>
                 </div>
              </div>
           </div>
         </form> 
        </div>

@endsection

0 likes
6 replies
Snapey's avatar
  • all form elements must have name= attributes

  • You cannot load a file input element with a value

  • present a small issue to be resolved, we are not interested in your whole form

  • please use three backticks ``` on its own line before and after your code blocks

1 like
AhmedMamdouh's avatar

2---> i want get the value of path of image in database 3--- > sorry for that .. i don't know why when i click on upload and submit it returns No in the hasFile condition in controller

Snapey's avatar

There are just too many errors in your form. Cut it down to the very basics and then build it up from there. Start with some basic tutorials and add images later.

Why have you shown two views here? which is it that has the problem?

this <form class="form-horizontal"> needs an action, a method and enctype

this <input type="file" value="{{$service->image}}" /> does not have a name for the input field, and cannot have a value attribute

Please format your code blocks in the forum so that we can see the code correctly.

AhmedMamdouh's avatar
               @foreach($services as $service)

                 
                     

here is the form action and method and enctype but i don't know why it doesn't appear

<form class="form-horizontal" action="{{ route('services.update',$service->id) }}" method="post" enctype="multipart/form-data">

   <div class="form-group">
    <label class="col-md-2 control-label">الصورة</label>
    <div class="col-md-10">
   <div class="fileinput fileinput-new input-group" data-provides="fileinput">
  <span class="input-group-addon btn btn-default btn-file">
 <span class="fileinput-new">تحميل ملف</span>
  <span class="fileinput-exists">تغيير</span>

  <input type="file" name="image" value="{{$service->image}}" />
   </span>
                              

حذف

حفظ التغيرات
        {{ csrf_field() }}         
        {{method_field('PATCH')}}
                    </div>

                    @endforeach
                 </div>
              </div>
              <!--  -->
           </div>
           
Snapey's avatar

ok, small improvement. You STILL don't format code blocks on the forum

You are in a foreach loop... Assuming this is because there are multiple services each with their own form. Is the submit button inside for foreach loop?

Does the form get sent to the server?

Have you dumped the request object in the controller?

You are still doing this <input type="file" name="image" value="{{$service->image}}" />

when this value="{{$service->image}}" makes no sense.

1 like
AhmedMamdouh's avatar

about the button yes it's inside the foreach loop

about the controller here's the update method in controller

    if($request->hasFile('image')){

       $request->image->store('public');

     }

     $service = Service::find($id);
        


     $service->image = $request->image;  
     $service->save();


    return redirect(route('services.index'));

what should i do in input because i don't understand you mean that i can't get value in the input ??

Please or to participate in this conversation.