Support the ongoing development of Laravel.io →
Input Laravel Forms
Last updated 2 years ago.
0

Uhm...

$request->file('customFile')

why did you not try this?

0

Thank's for u'r reply.

I have tried it too but empty too. I just forgot to put it in my exemple here. Anyway, i think that

$request->file('customFile')

is the same than

Input::file('customFile')
Last updated 5 years ago.
0

Well that is indeed weird then. Did you try to add

use Symfony\Component\HttpFoundation\File\UploadedFile;

into controller?

0

Yes. I found this tip during my research on the net. But unfortunately it does not change anything :(

0

Can you post the controller class definition and constructor? Maybe there is something wrong there

Also: what does $request->hasFile() return?

Last updated 5 years ago.
0

Ok. This is the whole Controller. Upload method is at the very bottom.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Custom\GoogleMap;
use App\Parlors;
use App\ParlorContacts;
use App\ParlorSchedules;
use App\ParlorPictures;
use App\ParlorTexts;
use App\Services;
use App\RatpStops;
use App\Massages;
use Illuminate\Support\Facades\Input;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class ParlorsController extends Controller
{
    /**
     * Liste des salons enregistrés
     */
    public function index() {
        $parlors = \Auth::user()->parlors()->get();

        return view('admin.parlors.home', [
            'parlors' => $parlors
        ]);
    }

    /**
     * Première étape de création d'un salon
     * @param Request $request
     */
    public function create(Request $request) {

        //Si c'est du get on vide la session et on affiche le formulaire
        if($request->getMethod() == 'GET') {
            session()->forget('parlorCreate');
            return view('admin.parlors.create');
        }

        //On génère la map via Google
        $img = GoogleMap::getStaticMapURL($request->get('latitude'), $request->get('longitude'));
        session( ['parlorCreate' => array_merge($request->all(), ['img' => $img])] );

        return response()->json( session('parlorCreate') );
    }

    /**
     * Deuxième étape de création d'un salon
     * @param $parlorId
     * @param Request $request
     */
    public function createStep2($parlorId, Request $request) {

        //Si on est en GET, on affiche le formulaire
        if($request->getMethod() == 'GET')
            return view('admin.parlors.createStep2', ['parlorID' => $parlorId]);

        //ON enregistre le téléphone
        ParlorContacts::add($parlorId, 'PHONE', $request->get('inputParlorPhone'));
        //On enregistre les plages horaires
        ParlorSchedules::add($request, $parlorId);

        return redirect('/admin/parlors/'.$parlorId);
    }

    /**
     * On va créer le salon en base depuis la session
     */
    public function save() {

        $parlor = Parlors::add();

        //On cherche les stations les plus proches et on les affecte si y'en à (que pour Paris/RATP)
        $stops = RatpStops::getStationsAround($parlor->location, 200);
        $parlor->stations()->attach($stops);

        return redirect('/admin/parlors/create/'.$parlor->id);
    }

    /**
     * Details d'un salon
     * @param $parlorId
     */
    public function details($parlorId) {

        $parlor = Parlors::find($parlorId);

        return view('admin/parlors/details', ['parlor' => $parlor]);
    }

    /**
     * Mise à jour des jours et horaires d'ouverture
     * @param $parlorId
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function editSchedule($parlorId, Request $request) {

        ParlorSchedules::add($request, $parlorId);

        return redirect('/admin/parlors/'.$parlorId);
    }

    /**
     * Mise à jour du text
     * @param $parlorId
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function editText($parlorId, Request $request) {

        ParlorTexts::add($parlorId, $request->get('text'));

        return redirect('/admin/parlors/'.$parlorId);
    }

    /**
     * Mise à jour des services
     * @param $parlorId
     * @param Request $request
     */
    public function editServices($parlorId, Request $request) {

        Services::add($parlorId, $request->all());

        return redirect('/admin/parlors/'.$parlorId);
    }

    public function editMassages($parlorId, Request $request) {
        Massages::add($parlorId, $request->all());

        return redirect('/admin/parlors/'.$parlorId);
    }

    /**
     * Modification d'un contact
     * @param $parlorId
     * @param $contactId
     * @param Request $request
     */
    public function editContact($parlorId, $contactId, Request $request) {

        ParlorContacts::edit($contactId, $request->get('value'));

        return redirect('/admin/parlors/'.$parlorId);
    }

    /**
     * Ajout d'un contact
     * @param $parlorId
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function addContact($parlorId, Request $request) {

        ParlorContacts::add($parlorId, $request->get('type'), $request->get('value'),false);

        return redirect('/admin/parlors/'.$parlorId);
    }

    /**
     * Suppression d'un contact
     * @param $parlorId
     * @param $contactId
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function deleteContact($parlorId, $contactId) {

        ParlorContacts::remove($contactId);

        return redirect('/admin/parlors/'.$parlorId);
    }

    /**
     * Upload d'une image pour le salon
     * @param $parlorId
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function uploadPicture($parlorId, Request $request) {

        return response()->json([
            '$_FILES' => $_FILES,
            'RequestAll' => $request->all(),
            'isValid' => $request->file('customFile')->isValid(),
            'Direct' => $request->customFile,
            'test' => Input::file('customFile'),
            'file' => $request->file('customFile')
        ]);
    }
}

0

Maaan I tried your code, this is interesting. Try this. Remove all code in uploadPicture and only return this

return $request->file('customFile')

Then, I do not know if json has some restrictions or what is going on why it shows empty value, but try also this

return response()->json([
   'file' => $request->file('customFile')->getClientOriginalName()
]);

it works! :)

Last updated 5 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Aurelien adsofts Joined 23 Feb 2019

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.