0

Hi i'm new using Laravel and i have a form with a upload file button, but this is optional on my form, if i don't want to upload an image, my app stores one by default (no-image.jpg) and this image is in my storage_path, how i can get this path and assign it to my new record?

I tried this but it doesn't work:

if($request->infopath == null){
    $request->infopath = public_path() . "/infopath"."/". 'no-image.jpg';
    PreguntaAbierta::create($request->all());
    Session::flash('store-success','Datos agregados correctamente!');
    return redirect()->route('abierta.index');
}

'SOLUTION'

I finally found a solution , although an unorthodox but it does what I want, but I doubt remains =/ On my view:

  @if($pregunta->infopath == null)
     <td><img src="infopath/no-image.jpg" alt="" style="width:100px"/></td>
  @endif

LOL

maudev
  • 974
  • 1
  • 14
  • 32
  • NOTE: i edited my storage_path() to public_path() but i think that this does not affect? – maudev Jul 14 '16 at 06:12
  • This looks an answer to your question. http://stackoverflow.com/questions/30191330/laravel-5-how-to-access-image-uploaded-in-storage-within-view – Musa Jul 14 '16 at 07:03

2 Answers2

0

You can use ->with

return redirect()->route('abierta.index')->with('infopath',$request->infopath);

and get this as $infopath in abierta.index

Also there is multiple option you can check here : https://laravel.com/docs/5.1/responses

Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109
  • Ty for ur reply, but i want to store an image by default when i don't upload one, my issue on this line : $request->infopath = public_path() . "/infopath"."/". 'no-image.jpg'; it dont saves my default image – maudev Jul 14 '16 at 06:19
  • did you tried to change like this : `$infopath = public_path() . "/infopath"."/". 'no-image.jpg';` instead of `$request->infopat` may be this is protected and we can't change it. – Niklesh Raut Jul 14 '16 at 06:21
  • Nop, neither.. when i print a real image path, it returns me: C:\xampp\tmp\php35E3.tmp it is generated for an image, i think that this is the path that i need, but i dont know how to get this .. – maudev Jul 14 '16 at 06:27
  • I think you should use `DIRECTORY_SEPARATOR` instead of \ or / – Niklesh Raut Jul 14 '16 at 06:29
0

You can do like this:

$input = $request->all();
$input['infopath'] = $your_image_public_path;
PreguntaAbierta::create($input);
im_tsm
  • 1,965
  • 17
  • 29