2017-01-13 5 views
0

Я пытаюсь вставить в таблицу изображений, но следующий синтаксис показывает, что метод save не выходит: BadMethodCallException в строке Macroable.php 74 :.Метод save не существует. Laravel

Контроллер:

foreach ($request->file('image') as $i) 
{ 
    $image = new image(); 

    $image = $i; 
    $input['imagename'] = $request->vname.'_'.$user->id.'_'.str_random(2).'.'.$image->getClientOriginalExtension(); 
    $destinationPath = public_path('/images'); 
    //move image to folder 
    $image->move($destinationPath, $input['imagename']); 

    $image->title=$input['imagename']; 
    $image->filepath=$destinationPath; 
    $image->Vehicle_id=$vehicles->id; 

    $image->save(); 

} 

Может кто-нибудь сказать мне, что я делаю неправильно?

+1

Добавьте полный метод пожалуйста (включая paramters) –

+0

** сохранить не существует: BadMethodCallException в Macroable.php линии 74 ** <- уход, чтобы отправлять версию Laravel и версии PHP? –

+4

Я думаю, что эта строка, вы назначили $ image = $ i; – Vineesh

ответ

3

Это сделает эту работу.

Вы заменили объект своей модели файлом здесь $image = $i;, поэтому нет способа сохранения для $image.

foreach ($request->file('image') as $file) 
{ 
    $image = new image(); 

    $input['imagename'] = $request->vname.'_'.$user->id.'_'.str_random(2).'.'.$file->getClientOriginalExtension(); 
    $destinationPath = public_path('/images'); 
    //move image to folder 
    $file->move($destinationPath, $input['imagename']); 

    $image->title=$input['imagename']; 
    $image->filepath=$destinationPath; 
    $image->Vehicle_id=$vehicles->id; 

    $image->save(); 

} 
+0

Спасибо. Это сработало! – Anon

Смежные вопросы