title: Laravel image upload to database
body: <p>This function is the function I use to store a new company:</p>
  <pre><code>public function store(Request $request)
  {   
  
      $file = $request-&gt;file('logo');
      $filename = 'company-logo-' . time() . '.' . $file-&gt;getClientOriginalExtension();
      $path = $file-&gt;storeAs('public', $filename);
      dd($path);            
  
      Company::create([
          'name' =&gt; $request-&gt;name,
          'email' =&gt; $request-&gt;email,
          'logo' =&gt; $request-&gt;logo,
          'website' =&gt; $request-&gt;website
      ]);
  
      return redirect('/company/all');
  }
  </code></pre>
  <p>This view is the one with the form:</p>
  <pre><code>@extends('layouts.app')
  
  @section('content')
      &lt;div class=&quot;card&quot;&gt;
          &lt;div class=&quot;card-body&quot;&gt;
              &lt;h4 class=&quot;card-title&quot;&gt;Create a Company&lt;/h4&gt;
          &lt;/div&gt;
  
          &lt;div class=&quot;container&quot;&gt;
              &lt;div class=&quot;jumbotron&quot;&gt;
                  &lt;ul class=&quot;list-group&quot;&gt;
                      &lt;li class=&quot;list-group-item&quot;&gt;
                          &lt;h3&gt;Enter Company Information:&lt;/h3&gt;
                          &lt;form action=&quot;{{ route('company.store') }}&quot; enctype=&quot;mutlipart/form-data&quot; method=&quot;POST&quot;&gt;
                              @csrf
                              &lt;div class=&quot;form-group&quot;&gt;
                                  &lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;name&quot; placeholder=&quot;Company name&quot; value=&quot;{{ old('name') }}&quot;&gt;
                              &lt;/div&gt;
                              &lt;div class=&quot;form-group&quot;&gt;
                                  &lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;email&quot; placeholder=&quot;Email&quot; value=&quot;{{ old('email') }}&quot;&gt;
                              &lt;/div&gt;
                              &lt;div class=&quot;form-group&quot;&gt;
                                  &lt;input class=&quot;form-control&quot; type=&quot;file&quot; name=&quot;logo&quot;&gt;
                              &lt;/div&gt;
                              &lt;div class=&quot;form-group&quot;&gt;
                                  &lt;input class=&quot;form-control&quot; type=&quot;url&quot; name=&quot;website&quot; placeholder=&quot;Website&quot; value=&quot;{{ old('website') }}&quot;&gt;
                              &lt;/div&gt;
                              &lt;button class=&quot;btn btn-primary&quot; type=&quot;submit&quot;&gt;Add Company&lt;/button&gt;
                          &lt;/form&gt;
                      &lt;/li&gt;
                  &lt;/ul&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  @endsection
  </code></pre>
  <p>This is the route:</p>
  <p>Route::post('/add', 'CompaniesController@store')-&gt;name('store');</p>
  <p>Well, what happens when I try to submit this form is that $file variable always returned with null:</p>
  <pre><code>Error
  Call to a member function getClientOriginalExtension() on null
  http://localhost:8000/company/add
  </code></pre>
  <p>Basically what I want to do is send the name of the image to the database and upload the image to my public folder. Neither happens with this code. when I erase the part starting from $file till dd($path); it adds the values to the database but the image hasn't been uploaded.</p>
  <p>Any help? Thanks in advance.</p>