0

I don't know how to edit image using laravel5. When I update my image file It show this error:

FatalErrorException in SiteadminController.php line 1719: Class 'App\Http\Controllers\Image' not found

Controller

 public function siteadmin_update_ads(Request $request)
    {


        $post = $request->all();
          $cid=$post['id'];  
         // $img=$post['ads_image'];

        $v=validator::make($request->all(),
                [
                    'ads_title'=>'required',
                    'ads_url' => 'required',

                ]
                );

        if($v->fails())
        {
            return redirect()->back()->withErrors($v->errors());
        }

         //$image = Image::find($cid);

        else 
        {
            $image = Image::find($cid);
            if($request->hasFile('ads_image'))
            {
                    $file = $request->file('ads_image');
                     $destination_path = '../assets/adsimage/';
                   $filename = str_random(6).'_'.$file->getClientOriginalName();
                   $file->move($destination_path, $filename);
                   $image->file = $destination_path . $filename;
            $data=array(

                'ads_title'=>$post['ads_title'],
                'ads_url'=>$post['ads_url'],
                'ads_image'=>$post['ads_image'],

            );
        }
        //  $image->caption = $request->input('caption');
        // $image->description = $request->input('description');
         $image->save();

        }
        // $i = DB::table('le_color')->where('id',$post['id'])->update($data);

        $i=Ads_model::update_ads($data,$cid);

            if($i>0)
            {
                Session::flash ('message_update', 'Record Updated Successfully');
                return redirect('siteadmin_manageads');
            }

        else {
 return Redirect('siteadmin_editads');

} }

Model

public static function update_ads($data,$cid)
    {
      return DB::table('le_ads')->where('id',$cid)->update($data);  
    }

View

<div class="item form-group">
    <label class="control-label col-md-3 col-sm-3 col-xs-12">Upload Image*</label>
    <div class="col-md-9 col-sm-6 col-xs-12">
      <input type='file' id="field" class='demo left' name='ads_image' data-type='image' data-max-size='2mb'/><br>
      <img src="{{ url('../assets/adsimage/').'/'.$row->ads_image}}" style="height:90px;">
    </div>
</div>
3
  • What is Image ? Is it a Model or Intervention Package ? Commented Dec 12, 2015 at 8:39
  • i am trying update my previous image using form Commented Dec 12, 2015 at 9:05
  • But what is Image here: $image = Image::find($cid);, that is what I am concerned with Commented Dec 12, 2015 at 9:06

2 Answers 2

1

I don't know what is that Image, so I am at least possible help to you. But I'll try to solve it.

What you can do is:

Add backslash \ before the Image. It should look like this: \Image::find($cid);

Or else, it is a Intervention package: you need to import the Facade of Intervention Package.

add use Intervention\Image\Facades\Image;

I hope this helps you out.

Sign up to request clarification or add additional context in comments.

Comments

0

you are missing the 'use' import statement for class image so its trying to find the class in the current namespace which is wrong assuming your model is stored at App namespace then add the below in the begining of controller

use App\Image

1 Comment

But it shows FatalErrorException in SiteadminController.php line 1719: Class 'App\Image' not found

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.