我收到奇怪的错误方法 Illuminate\Http\UploadedFile::backup 不存在

I'm getting strange error Method Illuminate\Http\UploadedFile::backup does not exist

我正在尝试使用 "Intervention image" 包在 Laravel 上以不同的分辨率将上传图片的大小调整 2 倍。这就是为什么我在调整大小之前使用 backup() 方法来存储图片的原始分辨率。但是当我 运行 我的代码出现错误 "Method Illuminate\Http\UploadedFile::backup does not exist." 有谁知道问题出在哪里?

Create.blade.php

@extends('layout')

@section('content')

<div class="container2">    
<div class="container">
        <div class="card card-container">
            <!-- <img class="profile-img-card" src="//lh3.googleusercontent.com/-6V8xOA6M7BA/AAAAAAAAAAI/AAAAAAAAAAA/rzlHcD0KYwo/photo.jpg?sz=120" alt="" /> -->
            <h1 style="text-align: center;">Napiši Vijest</h1>
       @if(count($errors) > 0) 
                  <div class="alert alert-danger">
                    <ul>
                    @foreach($errors ->all() as $error)
                    <li>{{$error}}</li>
                    @endforeach 
                    </ul>
                  </div>
  @endif

    {!! Form::open(['action' => 'MainController@store', 'method' => 'POST', 'files' => true]) !!}
      <div class="form-group">

            {{Form::label('postName', 'Ime')}}
            {{Form::text('postName', '', ['id' => 'postName', 'class' => ($errors->has('postName')) ? 'form-control is-invalid' : 'form-control',  'placeholder' => 'Unesite naslov'])}}

        </div>  
      <div class="form-group">

            {{Form::label('naslov', 'Naslov')}}
            {{Form::text('naslov', '', ['id' => 'inputname', 'class' => ($errors->has('naslov')) ? 'form-control is-invalid' : 'form-control',  'placeholder' => 'Unesite naslov'])}}

        </div>  

        <div class="form-group">
            {{Form::label('sadržaj', 'Sadržaj')}}
            {{Form::textarea('sadržaj', '', ['id' => 'inputtext', 'class' => ($errors->has('sadržaj')) ? 'form-control is-invalid' : 'form-control',  'placeholder' => 'Unesite sadržaj'])}}
        </div>  
    <div class="form-group">
         {{Form::label('file', 'Izaberi fajl')}}
        {{    Form::file('file') }}

    </div>  

    <div class="form-group">
        {{Form::label('slika', 'Izaberi sliku')}}
        {{Form::file('slika')}}

     </div>
      <div class="form-group">
            {{Form::label('Category', 'Izaberi kategoriju')}}
           {{Form::select('category', $category, null) }}
      </div>     
            {{Form::submit('Prihvati', ['class' => 'btn btn-success']) }}
                 <a href="{{URL::route('main')}}"  class="btn btn-info btn-xs proba" style="margin-right: 3px;">Početna strana</a>
         {!! Form::close() !!}




        </div><!-- /card-container -->
    </div><!-- /container -->
 </div><!-- /container -->


@endsection

Web.php

   Route::get('/createPost', 'MainController@create')->name('post.create')->middleware('admin');

Controller.php

<?php

namespace App\Http\Controllers;
use Auth;
use Illuminate\Http\Request;
use App\Http\Request2;
//including post model to controller
use validate;
use App\Post;
use App\Document;
use App\Category;
//if we want to use sql syntax for queries 
use DB; 
use File;
use Image;
use Mail;
use Session;
USE Validator;
use Redirect;
use Illuminate\Support\Facades\Input;

class MainController extends Controller
{

     public function create()
        {
           $category = Category::pluck('title', 'id');

           return View('create', compact('category',$category));
        }

        /**
         * Store a newly created resource in storage.
         *
         * @param  \Illuminate\Http\Request  $request
         * @return \Illuminate\Http\Response
         */
        public function store(Request $request)
        {   


      $rules = [
            'naslov' => 'required|min:3|max:20',
             'sadržaj' => 'required|min:40',
             'slika' => 'mimes:jpeg,bmp,png'

        ];
          $customMessages = [
            'required' => 'Unesite ":attribute" !',
            'min'  => 'Polje ":attribute" mora da ima minimum :min karaktera.',
             'max'  => 'Polje ":attribute" može da ima najviše :max karaktera.',
             'email'  => 'Polje ":attribute" mora da ima validan format',
             'mimes' => '":attribute" mora biti u sledećim formatima: :values'
        ];

        $validator =  Validator::make(Input::all(), $rules,  $customMessages);

        if ($validator->fails())
        {

    return \Redirect::back()->withErrors($validator)->withInput();
      }





            //create new post
            $post= new Post;
           $post -> name = $request -> input('postName');
            $post -> title = $request -> input('naslov');
            $post -> content = $request -> input('sadržaj');
            $post -> category_id = $request -> input('category');

         // Handle File Upload
         if( $request->hasFile('file') ) {
                   $filenameWithExt = $request->file('file')->getClientOriginalName();
                // Get just filename
                $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
                // Get just ext
                $extension = $request->file('file')->getClientOriginalExtension();
                // Filename to store
                $fileNameToStore= $filename.'_'.time().'.'.$extension;
                // Upload Image
                $path = $request->file('file')->storeAs('public/upload', $fileNameToStore);
                $post->file_name = $fileNameToStore;

            }

            // Check if file is present
            if( $request->hasFile('slika') ) {
                $post_thumbnail = $request->file('slika');
                $filename  = time() . '.' . $post_thumbnail->getClientOriginalExtension();
                 $post_thumbnail->backup();
                ini_set('memory_limit', '256M');
                $filename=Image::make($post_thumbnail);
                $filename->resize(329.33, 199.33)->save( public_path('uploads/' . $filename ) );

                $post->post_thumbnail = $filename;
            }

            $post->save();

              return redirect()->route('posts.show', $post)->with('successPost', 'Napisali ste novu vijest !');

    }

        }

你可以的,

//$post_thumbnail = Image::make($request->file('slika'));
//  $post_thumbnail->backup();


            $post_thumbnail = $request->file('slika');
            $filename  = time() . '.' . $post_thumbnail->getClientOriginalExtension();
             Image::make($post_thumbnail)->backup();
             ini_set('memory_limit', '256M');
            // $filename=Image::make($post_thumbnail);