A
A
Anon33632020-07-05 12:15:20
Laravel
Anon3363, 2020-07-05 12:15:20

I send a photo to the server and I get null in the output?

<form action="{{ url('AddProduct') }}" method="post" enctype="multipart/form-data">
                    @csrf
                    <div class="new-customers p-30">
                      <div class="row">
                        <div class="col-sm-6">
                          <input type="text"  placeholder="Product Name" name="productName">
                        </div>
                        <div class="col-sm-6">
                          <input type="text"  placeholder="Model" name="productType">
                        </div>
                        <div class="col-sm-6">
                          <select class="custom-select" name="category">
                            <option value="defalt">Category</option>
                            <option value="c-1">Notebook</option>
                            <option value="c-2">SmartPhone</option>
                            <option value="c-3">Acessory</option>
                            <option value="c-4">...</option>
                          </select>
                        </div>
                        <div class="col-sm-6">
                          <input type="text"  placeholder="Price..." name="price">
                        </div>
                      </div>
                      <input type="text"  placeholder="Count..." name="count">
                      
                      <!--Upload product photo -->

                      <div class="wrapper upload-photo">
                        <div class="container" style="max-width:100%;margin-left:20px;margin-bottom:20px;">
                          <div class="row">
                            <div class="col-2" style="margin-right:33px;">
                              <div class="box" style="height:120px;">
                                <div class="js--image-preview"></div>
                                <div class="upload-options">
                                  <label class="upload-lbl">
                                    <input type="file" class="product-image-upload" accept="image/*" name="productPhoto1" multiple/>
                                  </label>
                                </div>
                              </div>
                            </div>
</form>

<?php

namespace App\Http\Controllers;

use Redirect;
use Illuminate\Http\Request;
class ProductController extends Controller
{
   	public function AddProduct(Request $r){
   		$data = $r->file('');
   		dd($data);
   		return Redirect::to('my-account');
   	}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2020-07-05
@Yadalay

$data = $r->file('productPhoto1');
If attaching images is optional, then wrap the logic tied to them in a condition:

if ($r->hasFile('productPhoto1')) {
    $data = $r->file('productPhoto1');
    // Описание логики.
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question