Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

941
Vistas
Laravel 8 Call to a member function extension() on null

I am trying to upload an image in Laravel 8, after changing the file path to public in the config folder and setting up the Model properly. I am getting this response

Call to a member function extension() on null

My Product controller

 public function store(Request $request)
    {
        $file = $request->file('image');
        $name = Str::random(10);
        $url = Storage::putFileAs('images', $file, $name . '.' . $file->extension());

        $product = Product::create([
            'title' => $request -> input('title'),
            'description' => $request -> input('description'),
            'image' => env('APP_URL') . '/' . $url,
            'price' => $request -> input('price'),
        ]);

        return $product;
    }

My model

protected $guarded = ['id'];

Migration

public function up()
   {
        Schema::create('products', function (Blueprint $table) {
            $table->id();
            $table->string('title');
            $table->string('description')->nullable();
            $table->string('image');
            $table->decimal('price');
            $table->timestamps();
        });
    }

What have I done wrong or what am I not doing right please?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Verify that you have a file before creating the product. Or do a proper validation of all required fields.

public function store(Request $request)
    {
        if (!$request->has('image')) {
            return response()->json(['message' => 'Missing file'], 422);
        }
        $file = $request->file('image');
        $name = Str::random(10);
        $url = Storage::putFileAs('images', $file, $name . '.' . $file->extension());

        $product = Product::create([
            'title' => $request -> input('title'),
            'description' => $request -> input('description'),
            'image' => env('APP_URL') . '/' . $url,
            'price' => $request -> input('price'),
        ]);

        return $product;
    }
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda