@cpt_pall change $articles to $article
$article->photos()->attach([$imagedata->id]);
Hello, i try write my update method to upload article with photo and gallery images but i don't know how. My store method works but with update method i have a problem
public function update(Request $request, $id)
{
if( $request->hasFile('photo') ) {
$file = $request->file('photo');
$fileName = $file->getClientOriginalName();
$path = 'uploads';
$file = $file->move($path, $fileName);
}
$article = Article::whereId($id)->firstOrFail();
$article->title = $request->get('title');
$article->description = $request->get('description');
$article->image = $request->get('photo');
$article->save();
$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($articles);
}
Please or to participate in this conversation.