dimanche 31 janvier 2016

Laravel 5.0 Upload File using Storage API always returns Forbidden

I'm new to Laravel and I'm trying to upload images to my website using Storage API but laravel always returns "Forbidden" after I submitted my form.

Here's my form (add_company.blade.php) :

{!! Form::model($company = new App\Models\Setting\Organization\Company, ['method' => 'POST', 'action' => 'Setting\Organization\CompaniesController@store', 'files'=>true]) !!}

    <div class="form-group">
        {!! Form::label('CompanyCode', 'Company Code : ', ['class' => 'col-lg-3 col-md-3 col-sm-3 col-xs-3']) !!}

        <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9">
            {!! Form::text('CompanyCode', $company->autoGenerateCode(), ['class' => 'form-control', 'readonly' => true]) !!}
        </div>

    </div>

    <div class="form-group">
        {!! Form::label('Name', 'Company Name : ', ['class' => 'col-lg-3 col-md-3 col-sm-3 col-xs-3']) !!}

        <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9">
            {!! Form::text('Name', null, ['class' => 'form-control']) !!}
        </div>

    </div>

    <div class="form-group">
        {!! Form::label('Logo', 'Company Logo : ', ['class' => 'col-lg-3 col-md-3 col-sm-3 col-xs-3']) !!}

        <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
            <span class="btn btn-default btn-file form-control">
                Browse {!! Form::file('Logo', ['class' => 'form-control', 'id' => 'logo']) !!}
            </span>
        </div>

    </div>

    <div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
        {!! Form::submit('Add Company', ['class' => 'btn btn-primary']) !!}
    </div>
{!! Form::close() !!}

Here's the store method in my controller (App\Http\Controllers\Setting\Organization\CompaniesController) :

public function store(CompanyRequest $request){
    if (Request::file('Logo')->isValid())
    {
        $file = Request::file('Logo');
        $extension = $file->getClientOriginalExtension();
        $newFilename = $request->CompanyCode . "_logo";
        Storage::disk('local')->put($newFilename . '.' . $extension,  File::get($file));

        $request->Logo = $newFilename;
    }

    Company::create($request->all());
    flash()->success('Company ' . $request->Name . ' Added.');
    return redirect('company');
}

Laravel doesn't give any error but always returns "Forbidden" every time I submit my form. I didn't change anything in the config/filesystems.php or in the public/.htaccess.

Please help, I've already read many posts about file upload in Laravel 5 but didn't find any answer. Thanks a lot!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1SjY3Me
via IFTTT

Aucun commentaire:

Enregistrer un commentaire