Я пытаюсь получить данные из формы и сохранить их в БД. Форма включает в себя загрузку изображений.
Когда я пытаюсь выполнить приведенный ниже код (это все, что я знаю), я получаю «Вызов функции-члена save () on array». Я не уверен, как изменить код, чтобы сделать его правильным
Контроллер
public function store(Request $request){
//
$input = $request->all();
$input->save();
if($file = $request->file('image')){
$name = $file->getClientOriginalName();
if($file->move('image', $name)){
$post = new Gallery();
$post->image = $name;
$post->save();
return redirect()->route('admin.gallery.index');
};
};
}
Создание клинка
@extends('layouts.admin')
@section('content')
<h1>UPLOAD PICTURES</h1>
{!! Form::open(['method' =>'POST', 'action'=> 'GalleryController@store',
'files'=>true, 'enctype'=>'multipart/form-data']) !!}
<div class="form-group">
{!! Form::label('Picture:') !!}
{!! Form::file('image', null, ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::label('species_id', 'Species:') !!}
{!! Form::select('species_id', [''=>'Choose Species'] + $species, null,
['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::label('name', 'Image Title:') !!}
{!! Form::text('name', null, ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::label('patreon', 'Patreon Image?:') !!}
{!! Form::select('patreon', array(1 =>'Yes', 0=>'No'), 0,['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::submit('Upload Image', ['class'=>'btn btn-primary']) !!}
@endsection
Модель
namespace App;
use Illuminate\Database\Eloquent\Model;
class Gallery extends Model
{
//
protected $fillable = [
'image',
'species_id',
'name',
'tag',
'patreon'
];
public function species(){
return $this->belongsTo('App\Species');
}
}