SetKyarWaLar's avatar

Uploading Image null on Laravel 5.0

I had created a form like the following in my view

{!! Form::open(array('url' => 'user/posts', 'files'=> true)) !!}
           <div class="form-group">
               {!! Form::text('title',Input::old('title'),['class'=>'form-control', 'placeholder' => 'What is your title?']) !!}
           </div>
           <div class="form-group">
              {!! Form::label('image', 'Your Image') !!}
              {!! Form::file('image') !!}
             <p class="help-block">Hey! Please don't upload over 15MB images!</p>
           </div>
           <div class="form-group">
            {!! Form::label('caption', 'Don\'t miss to caption!') !!}
            {!! Form::text('caption',Input::old('caption'),['class'=>'form-control', 'placeholder' => 'Your caption']) !!}
           </div>
           {!! Form::submit('Post  now!',['class'=>'btn btn-info']) !!}
      {!!Form::close() !!}

And I try dd() for my image from my controller but it return nulll.

public function store(PostFormRequest $request)
    {   
  dd($request->input('image'));
  $post = new Post;
    }

The following one is my PostFormRequest

<?php namespace App\Http\Requests;

use Response;
use Illuminate\Foundation\Http\FormRequest;

class PostFormRequest extends FormRequest {

    public function rules()
    {
        return [
            'title' => 'required',
            'image' => 'mimes:jpeg,bmp,png'
        ];
    }

    public function  authorize()
    {   
     $image = $this->image;
     if(empty($image))
      return true;
     else 
      return false;
    }

    public function forbiddenResponse()
    {
        return Response::make('Sorry!',403);
    }
}
0 likes
5 replies
SetKyarWaLar's avatar

When I try dd($request->input('title')); it's return string(4) "test" .When I try $input = $request->all(); dd($input); from my controller I got like the following. What I was wrong?

array(4) { ["_token"]=> string(40) "m07GGQnU8W2rtbtLYsPSHohrnQYSPwBUX1H7tlMR" ["title"]=> string(4) "test" ["caption"]=> string(4) "test" ["image"]=> object(Symfony\Component\HttpFoundation\File\UploadedFile)#9 (7) { ["test":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> bool(false) ["originalName":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> string(11) "images.jpeg" ["mimeType":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> string(10) "image/jpeg" ["size":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> int(4922) ["error":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=> int(0) ["pathName":"SplFileInfo":private]=> string(14) "/tmp/phppxCnDA" ["fileName":"SplFileInfo":private]=> string(9) "phppxCnDA" } }
bashy's avatar

Input::file() and Input::get() (or equivalent) are different and have been in the documentation for a long time.

1 like

Please or to participate in this conversation.