Storing data with Laravel 5.3 using Storage::put and XMLHttpRequest

Attempting to send a file using DRAG & DROP with XMLHttpRequest.

$images = $_FILES['images'];

When I use foreach:

foreach($images["name"] as $file => $name)

and

move_uploaded_file($images["tmp_name"][$file], $images_dir . $name

it works fine but I want to utilize

Storage::put

but it doesn't work

I have:

use Illuminate\Support\Facades.Storage;

and in filesystems.php

'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'visibility' => 'public',
        ],

When I hover over 'put' in my PHPStorm IDE, it shows

"Method 'put' not found in Illuminate\Support\Facades\Storage"

class Storage extends Facade but there is no 'put' method in Facade. What could be the issue with Storage ?

Answer №1

Try replacing the usage of

Illuminate\Support\Facades\Storage
with simply use Storage

Don't get sidetracked by IDE errors, just test if it's functioning correctly. Laravel leverages magic methods and various architectural patterns which may not be fully supported by all IDEs.

Avoid relying on $_FILES, instead use this method:

$files = $request->input('images');
foreach($files as $key => $value) {
    if ($request->hasFile('images.' . $key)) {
        $file = $request->file('images.' . $key);
        $filename = $file->getClientOriginalName();
        Storage::put($filename, file_get_contents($file));
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Inquiring about class variables

Can you explain the purpose of these variable declarations within a PHP class: class VbForumsPageMain extends BxDolPageView { var $_oMain; var $_oTemplate; var $_oConfig; var $_oDb; function VbForumsPageMain(&$oMain) { $th ...

Refresh the Server Component once data has been modified by the Client Component within Next.js

I am still grappling with this specific scenario and trying to figure out the best approach in Next.js 13. Can anyone provide guidance on the correct way to handle this? In a Server Component, I have a list of users being displayed, leveraging MongoDB, as ...

Displaying information in a drop-down list based on the selection made in a previous drop

Hey fellow developers, I could really use your expertise on a project I'm working on for attendance management. I've hit a roadblock with a specific feature - my goal is to dynamically display departments based on the selected block without requi ...

What is the best way to determine if an application has been installed on an Android device while browsing a website?

Let's set the scene: I've got a website that needs to use JavaScript to determine whether my app is already installed on the android device it's currently being used on. If the app is installed, the page will display a link (with a custom ...

Deciphering the intricacies of a 400 bad request error within an

I initially believed there was an issue in my code, but upon further testing, I have encountered some unexpected behavior that I would like to investigate. So, here is a basic API route: Route::group(['prefix' => 'api/v1'], functio ...

Cypress: Uncovering the method invoked by a button click

I'm currently utilizing Vue3 with Vite and Cypress. My Vue3 component utilizes the script setup SFC syntax. Below is the code snippet for my component: <template> <div> <button data-cy="testBtn" @click="btnClick()&q ...

Issue: 'The server cannot be started because the path is not defined' error message appears

Hey everyone, I'm currently working on implementing a forgot/reset password feature for my React Native app using this tutorial. However, when attempting to start the server, I encountered an error related to the 'path'. ReferenceError: pat ...

When using an `if` statement in CSS to determine if the value of `left` is

Is there a way to trigger an event only when the object reaches a specific percentage of its left position? I am trying to achieve this using jQuery with the .css() method. Here is what I have so far: HTML: <div id="midDiv"><img ..../></di ...

Enhance Laradock by integrating a personalized npm package

Although it's a bit unconventional, I have found a temporary solution to my issue. I currently have laradock installed on my system along with my Laravel app. Within laradock, the command docker-compose up -d nginx mysql php-worker workspace redis pr ...

What do you notice about interactions involving 'input type=text' in HTML and JavaScript?

When a new binding is created for the value property on an input, any manual modifications by the user no longer update the value. What happens when the binding is altered? Does regular user interaction involve key press listeners? I've modified the ...

Shifting the entire page from left to right and back again

I am in search for a template that moves the page from left to right. If anyone can guide me on how to create this effect or provide a JavaScript example, I would greatly appreciate it. ...

The nested click event is not functioning as expected

Below is a simplified version of HTML code containing 2 nested click events (one on the href and one on an input). When the user clicks on the input field, it inadvertently triggers the javascript function SelectTable() linked to the href event. This unint ...

Preserve Text Selection While Utilizing DIV as a Button

I wonder if this issue is specific to the browser I'm using? Currently, I'm using Chrome... My goal is to enable users to save any text they've highlighted on the page with their cursor. I've set up the javascript/jQuery/ajax and it w ...

Exploring the capabilities of Socket.IO in Node.js for establishing a connection with an external server

Background: My localhost (referred to as Server A) hosts a node.js server, while an external server running node.js can be found at (known as Server B). Although I lack control or access over Server B, which serves as a dashboard site for an IoT device in ...

When the button is clicked, I desire to reveal the background color of a specific div

<div class="mat-list-item" *ngIf="authService.isAdmin()" (click)="openModal('site-settings', site.siteID)"> <span class="mat-list-item-content">{{ "Application.site_settings_label&q ...

The Vue-cli webpack development server refuses to overlook certain selected files

I am attempting to exclude all *.html files so that the webpack devserver does not reload when those files change. Here is what my configuration looks like: const path = require('path'); module.exports = { pages: { index: ...

What are the best ways to format an outgoing email using inline CSS?

On my upcoming website, I have set up a single form for guests to subscribe. The issue I am facing is with styling the email that is sent upon submission. I attempted using inline CSS, but it doesn't seem to be working. Instead of transforming the cod ...

Ensuring that an added row remains at the bottom of a table composed of rows generated dynamically by utilizing the .detach() method

I need to ensure that the "subtot" row is always appended as the last row in the table. When dynamically adding rows, the "subtot" row appears as the last row the first time, but does not stay at the bottom when more rows are added. Even though I want the ...

Trouble with top attribute functionality within animate function

Why does the top attribute in the animate function of JQuery not seem to work, while the opacity attribute functions correctly in the code snippet below? $(function() { $(window).on('scroll', function() { ...

Bidirectional Doctrine2 ManyToMany attribute being populated through the use of the find method

I am looking to generate entities from an existing database, specifically for an N - N relation that creates an articlesCategories table. Currently, I have two entities: Article and Category, and I aim to establish a ManyToMany bidirectional relationship ...