title: how to resize image in Laravel and save data in database at the same time
body: <p>i'm trying to pass data(title,description and resized image) to my database</p>
  <p>this is the store function, for now it saves my images in that path but it doesn't save them in the database</p>
  <p>the store function can work if i remove the resize image.</p>
  <pre><code>    public function store(Request $request)
  {
      $request-&gt;validate([
          'title' =&gt; 'required',
          'image' =&gt; 'required|image|mimes:jpg,png,jpeg,gif,svg|max:10240',
          'description' =&gt; 'required',
      ]);
  
      $path = $request-&gt;file('image');
      $filename = $path-&gt;getClientOriginalName();
      $image_resize = Image::make($path-&gt;getRealPath()); 
      $image_resize-&gt;resize(800, 800);             
      $image_resize-&gt;save(public_path('images/' .$filename));
  
      $post = new Post;
  
      $post-&gt;title = $request-&gt;title;
      $post-&gt;description = $request-&gt;description;
      $post-&gt;image = $image_resize;
  
      $post-&gt;save();
  
   
      return redirect()-&gt;route('posts.index')
                      -&gt;with('success','Post has been created successfully.');
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Yb75u.png" rel="nofollow noreferrer">enter image description here</a>
  <a href="https://i.stack.imgur.com/NwGuE.png" rel="nofollow noreferrer">enter image description here</a></p>
  <p>this is the new store function</p>
  <pre><code>public function store(Request $request)
  {
      $request-&gt;validate([
          'title' =&gt; 'required',
          'image' =&gt; 'required|image|mimes:jpg,png,jpeg,gif,svg|max:10240',
          'description' =&gt; 'required',
      ]);
  
      $path = $request-&gt;file('image');
      $filename = $path-&gt;getClientOriginalName();
      $image_resize = Image::make($path-&gt;getRealPath()); 
      $image_resize-&gt;resize(800, 800);             
      $image_resize-&gt;save(public_path('images/' .$filename));
  
      $post = new Post;
  
      $post-&gt;title = $request-&gt;title;
      $post-&gt;description = $request-&gt;description;
      $post-&gt;image = 'images/' .$filename;
  
      $post-&gt;save();
  
   
      return redirect()-&gt;route('posts.index')
                      -&gt;with('success','Post has been created successfully.');
  }
  </code></pre>
  <p>this the blade code</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;Laravel 8 CRUD Tutorial&lt;/title&gt;
  
      &lt;link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" &gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div class="container mt-2"&gt;
  
  &lt;div class="row"&gt;
          &lt;div class="col-lg-12 margin-tb"&gt;
              &lt;div class="pull-left"&gt;
                  &lt;h2&gt;Laravel 8 Post CRUD Tutorial&lt;/h2&gt;
              &lt;/div&gt;
              &lt;div class="pull-right mb-2"&gt;
                  &lt;a class="btn btn-success" href="{{ route('posts.create') }}"&gt; Create New Post&lt;/a&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
     
      @if ($message = Session::get('success'))
          &lt;div class="alert alert-success"&gt;
              &lt;p&gt;{{ $message }}&lt;/p&gt;
          &lt;/div&gt;
      @endif
     
      &lt;table class="table table-bordered"&gt;
          &lt;tr&gt;
              &lt;th&gt;S.No&lt;/th&gt;
              &lt;th&gt;Image&lt;/th&gt;
              &lt;th&gt;Title&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
              &lt;th width="280px"&gt;Action&lt;/th&gt;
          &lt;/tr&gt;
          @foreach ($posts as $post)
          &lt;tr&gt;
              &lt;td&gt;{{ $post-&gt;id }}&lt;/td&gt;
              &lt;td&gt;&lt;img src="{{ Storage::url($post-&gt;image) }}" height="75" width="75" alt="" /&gt;&lt;/td&gt;
              &lt;td&gt;{{ $post-&gt;title }}&lt;/td&gt;
              &lt;td&gt;{{ $post-&gt;description }}&lt;/td&gt;
              &lt;td&gt;
                  &lt;form action="{{ route('posts.destroy',$post-&gt;id) }}" method="POST"&gt;
      
                      &lt;a class="btn btn-primary" href="{{ route('posts.edit',$post-&gt;id) }}"&gt;Edit&lt;/a&gt;
     
                      @csrf
                      @method('DELETE')
        
                      &lt;button type="submit" class="btn btn-danger"&gt;Delete&lt;/button&gt;
                  &lt;/form&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          @endforeach
      &lt;/table&gt;
    
      {!! $posts-&gt;links() !!}
  
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>