1

i'm trying to let my users upload a .pdf file but when calling the putFile method or the putFileAs method i get the following error:

Call to a member function hashName() on null in \vendor\laravel\framework\src\Illuminate\Filesystem\FilesystemAdapter.php:146

checking the $file propery of the putFile method returns null. However when I dd the given argument it returns (as it looks to me) a normal file.

it returns the following publication_file in whoops

array:5 [▼
  "name" => "users-tragos.pdf"
  "type" => "application/pdf"
  "tmp_name" => "C:\xampp\tmp\phpAB1F.tmp"
  "error" => 0
  "size" => 205603
]

My controller code is:

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Carbon\Carbon;
use App\Http\Controllers\Controller;
use App\publication;
use App\User;

class publicationsController extends Controller
{

public function store(Request $request){
    $this->validate($request, [
    'title' => 'required',
    'author' => 'required',
    'publication_date' => 'required|date_format:m/Y'
    ]);

    if($request->filled("publication_url")){
        $this->validate($request, [
        'publication_url' => 'url'
        ]);

    }
    if($request->filled("publication_file")){
        $this->validate($request, [
        'publication_file' => 'file|mimes:pdf|max:10000'
        ]);
    }

    $publication_date = carbon::createFromFormat('m/Y', request("publication_date"))->format('Y-m-d');


    if($request->hasFile('publication_file')){
        if($request->file('publication_file')->isValid()){
            $path = Storage::putFile('publications', $request->file('publication_file'));
        }
    }
}

my form code is:

<form method="POST" action="/publications" id="form_table" enctype="multipart/form-data">
{{ csrf_field() }}
<table>
<tr><td><label for="title">Title</label></td><td><input type="text" name="title" id="title" required autofocus /></td></tr>
<tr><td><label for="title">Author</label></td><td><input type="text" name="author" id="author" required /></td></tr>
<tr><td><label for="publication_date">Publication Date</label></td><td>
<input type="text" name="publication_date" id="publication_date" required placeholder="mm/yyyy"/></td></tr>
<tr><td colspan="2"><label for="content">Content</label><br /><br />
<textarea name="body" id="content"></textarea></td></tr>
<tr><td><label for="publication_file">Upload .pdf file</label></td><td>
<input type="file" id="publication_file" name="publication_file" accept="application/pdf" /></td></tr>
<tr><td><label for="publication_url">Link to file</label></td><td><input type="text" id="publication_url" name="publication_url" /></td></tr>
<tr><td><button type="submit" value="submit"/>submit</button></td></tr>
</table>
</form>

Does anyone know how to fix this? I am using Laravel 5.5

Vision Coderz
  • 8,257
  • 5
  • 41
  • 57
  • Possible duplicate of [Call to a member function store() on null - laravel 5.4](https://stackoverflow.com/questions/42089208/call-to-a-member-function-store-on-null-laravel-5-4) – CSchulz Sep 19 '17 at 09:19
  • 1
    Fixed. Stupid mistake that there was a not commented putFile reminder with incorrect input – Marijn Struijlaart Sep 19 '17 at 09:43

0 Answers0