Level 30
I love these sentences "does not work"!
What does not work? Are you getting an error message? Which error message?
1 like
I try write a method which a create a new Article with title,content,main photo and gallery but my method doesn't work
public function doNews(Request $request)
{
if( $request->hasFile('photo') ) {
$file = $request->file('photo');
$fileName = $file->getClientOriginalName();
$path = 'uploads';
$file = $file->move($path, $fileName);
}
$articles = new Article(array(
'title' => $request->get('title'),
'description' => $request->get('description'),
'photo' => $path.'/'.$fileName,
));
$photos = Input::file('images');
foreach($photos as $photo):
$move = $photo->move('public/images', $photo->getClientOriginalName());
if($move)
{
$imagedata = Photo::create([
'title'=> $photo->getClientOriginalName(),
'filename' => $photo->getClientOriginalName()
]);
$articles->photos()->attach([$imagedata->id]);
}
endforeach;
dd($images);
}
Please or to participate in this conversation.