skip to Main Content

I want to save the route of an image in the database. In my table I have an image field which is a string field.

And the code to save the image is this:

Question::create([
            'title' => $request->title,
            'slug' => $request->slug,
            'image' => Storage::put('imagenapp', $request->file('image')),
            'evaluation_id' => $request->evaluation_id,
            'type' => "OMI",
            
        ]);

The input in the view is this:

<input type="file" name="image" id="image" class="form-control-file" accept="image/*">

I already have changed this line of code in filesystems.php file:

'default' => env('FILESYSTEM_DISK', 'public'),

And this line in the .env file:

FILESYSTEM_DISK=public

But when I try to store the data in the database I have the next error:

LeagueFlysystemFilesystem::write(): Argument #2 ($contents) must be of type string, null given, called in C:xampphtdocsaplicacionunovendorlaravelframeworksrcIlluminateFilesystemFilesystemAdapter.php on line 360

2

Answers


  1. Chosen as BEST ANSWER

    I found the mistake, I missed this code in the form:

    enctype="multipart/form-data"
    

  2. Try this

    create([
      'title' => $request->title,
      'slug' => $request->slug,
      'image' => $request->file('image')->storeAs('imagenapp', uniqid(rand()) . '.' .  $request->image->extension()),
      'evaluation_id' => $request->evaluation_id,
      'type' => "OMI",      
    ]);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search