title: laravel 6 : Call to a member function store() on null
body: <p>I am trying to attach a file to a blog type post. For this i have an file field and 2 buttons, one saves the fields to the database and the other uploads the file. standalone the file upload works as intended. However in the form i get <strong>Call to a member function store() on null</strong>. I have changed the menthod from put to  post, but that doesnt seem have any effect.</p>
  <p>Below my post forms and the function in the controllers.</p>
  <p>The Form:</p>
  <pre><code>&lt;div class=&quot;container&quot;&gt;
      &lt;div class=&quot;row justify-content-center&quot;&gt;
          &lt;div class=&quot;col-md-8&quot;&gt;
              &lt;div class=&quot;card&quot;&gt;
                  &lt;div class=&quot;card-header&quot;&gt;New/Edit Blog&lt;/div&gt;
                  &lt;div class=&quot;card-body&quot;&gt;
                     @if($data)
                  &lt;form … action = &quot;{{Route ('post.update', $data-&gt;_id)}}&quot; method=&quot;post&quot;, enctype = 'multipart/data'&gt;
                      @csrf
                      @method('POST')
                      &lt;div class=&quot;form-group&quot;&gt;
                          &lt;label for=&quot;usr&quot;&gt;Title:&lt;/label&gt;
                          &lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;title&quot; value = &quot;{{$data-&gt;title}}&quot; &gt;
                        &lt;/div&gt;
  
                        &lt;div class=&quot;form-group&quot;&gt;
                          &lt;label for=&quot;shorttext&quot;&gt;Shorttext:&lt;/label&gt;
                          &lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;shorttext&quot; value = &quot;{{$data-&gt;shorttext}}&quot; &gt;
                        &lt;/div&gt;
  
                            &lt;div&gt;
                            &lt;input id=&quot;x&quot; type=&quot;hidden&quot; name=&quot;content&quot; value =&quot;{{$data-&gt;content}}&quot;&gt;
                            &lt;trix-editor input=&quot;x&quot; &gt;&lt;/trix-editor&gt;
                          &lt;/div&gt;
                   
                      
                      &lt;div class=&quot;form-group&quot;&gt;
                          &lt;label for=&quot;created_by&quot;&gt;Created By:&lt;/label&gt;
                          &lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;created_by&quot; value = &quot;{{$data-&gt;created_by}}&quot; readonly&gt;
                        &lt;/div&gt;
                       
                        &lt;input type=&quot;file&quot; name=&quot;attachment&quot; enctype=&quot;multipart/form-data&quot;/&gt;
                      &lt;p align=&quot;center&quot;&gt;
                        &lt;input type=&quot;submit&quot; btn btn-primary class=&quot;btn btn-primary&quot; id=&quot;save&quot; name=&quot;action&quot; value=&quot;save&quot;&gt;
                     
                        &lt;input type=&quot;submit&quot; btn btn-primary class=&quot;btn btn-primary&quot; id=&quot;upload&quot; name=&quot;action&quot; value=&quot;upload&quot;&gt;
  </code></pre>
  <p>The functions in the controller:</p>
  <p>Store:( this one is the function that determines which button is pressed)</p>
  <pre><code>public function store(Request $request, $_id = false, $attachment = false){
          //check which submit was clicked on
          if($request-&gt;action == 'upload'){
              //
              $this-&gt;upload($request);
              return redirect()-&gt;route('home');
          } elseif($request-&gt;action == 'save') {
              //echo 'save pressed';
              //run function save all form fields
             
              $this-&gt;update($request, $_id);
              return redirect()-&gt;route('home');
  
           } else {echo &quot;error&quot;;}
     }
  </code></pre>
  <p>Upload function:</p>
  <pre><code>function upload(Request $request){
  
          $path = $request-&gt;file('attachment');
         // $original = $request-&gt;file('attachment')-&gt;getClientOriginalName();
          
          $path-&gt;store('/public');
  </code></pre>
  <p>Update function:</p>
  <pre><code>public function update (Request $request,  $_id){
          
          //$this-&gt;upload($request);
  /* 
          $path = $request-&gt;file('attachment');
          $path-&gt;storeas('/public','123'); */
          
          $data = post::findOrFail($_id);
  
          $data-&gt;title    = $request-&gt;title;
          $data-&gt;content  = $request-&gt;content;
          $data-&gt;shorttext  = $request-&gt;shorttext;
          $data-&gt;created_by  = $request-&gt;created_by;
          $data-&gt;text3  = $request-&gt;text3;
          $data-&gt;attachment  = $request-&gt;attachment;
         
          $data-&gt;save();
  
      
          if($data){
              return redirect()-&gt;route('home');
      
          }else{
              return back();
              }
          }
  </code></pre>
  <p>The route is:</p>
  <pre><code>Route::post('/post/update/{_id}', 'PostController@store')-&gt;name('post.update');
  </code></pre>
  <p>As mentioned, the save function in the complete form works. In a standalone form ( and a standalone controller) the upload works (and i can, if i wish, manipulate the filename), but how do i bring the 2 together? At first i thought it was because the update form had a PUT method, but changing everything to post doesnt seem to have any effect and i still get the Null error.</p>
  <p>For completeness the standalone solution:</p>
  <p>Controller:</p>
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  use Te7aHoudini\LaravelTrix\Pipes\AttachmentInput;
  
  class UploadController extends Controller
  {
      //
      function upload(Request $req){
  
  $path = $req-&gt;file('attachment');
  $original = $req-&gt;file('attachment')-&gt;getClientOriginalName();
  
  $path-&gt;storeas('/public',$original);
  echo $original;
  
         
      }
  
  }
  </code></pre>
  <p>The standalone form:</p>
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Upload&lt;/title&gt;
  &lt;/head&gt;
  &lt;/html&gt;
  &lt;form action=&quot;upload&quot; method=&quot;POST&quot; enctype=&quot;multipart/form-data&quot;&gt;
  &lt;input type=&quot;file&quot; name=&quot;attachment&quot; /&gt;
  @csrf
  
  &lt;button type=&quot;submit&quot;&gt;file upload&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>