use this to get the image filename
$request->file('img')
Hello guys,
I'm facing a problem when trying to upload an image in a repeating field, here is a part of my form:
{!! Form::label('name','Image') !!}
{!! Form::file('img[]', null, ['class'=>'form-control']) !!}
Here are my casts:
protected $casts = [
'title' => 'array',
'desc' => 'array',
'img' => 'array',
];
}
Here is my Store method:
public function store(Request $request)
{
$files = Input::file('img');
foreach($files as $file) {
$destinationPath = public_path('/images/uploads/');
$filename = $file->getClientOriginalName();
$file->move($destinationPath, $filename);
$test['img'] = $filename;
}
$this->test->create($request->all());
return redirect()->route('admin.tests');
}
I can make the Title and Desc work but when trying to upload an image I get this:
App\Test {#726
id: "15",
title: "["test1"]",
desc: "["test2"]",
img: "[{}]",
created_at: "2016-03-29 03:16:39",
updated_at: "2016-03-29 03:16:39",
},
How can my img column receive the path instead of '{}' only?
Thanks!
Please or to participate in this conversation.