I'm trying to save multiple images of my property, a property can have several images, but I get this error
I would like to know what it produces if you can help me here I leave my controller in the store function
code upload image
public function store(Request $request)
{
/*--from this session you start to save the properties with all their attributes --*/
$properti = new Propertie;
$detail = new Detail;
$detail->antiquity = $request->antiquity;
$detail->furnished = $request->furnished;
$detail->floor = $request->floor;
$detail->save();
$properti->details_id = $detail->id;
$properti->name = $request->name;
$properti->price = $request->price;
$properti->description = $request->description;
$properti->departaments_id = $request->departaments;
$properti->municipalities_id = $request->municipalities;
$properti->property_type_id = $request->type_property;
$properti->offer_type_id = $request->type;
$properti->details_id = $detail->id;
$properti->images = $request->images;
$properti->lat = $request->lat;
$properti->lng = $request->lng;
$properti->address = $request->address;
if (isset($request->property_id)) {
$property_type = $request->property_id;
} else {
$property_type = null;
}
$images=array();
if($files=$request->file('images')){
foreach($files as $file){
$name=$file->getClientOriginalName();
$file->move('image',$name);
$images[]=$name;
}
}
$properti->save();
$piso_id = $properti->id;
$space = new Space;
$space->property_id = $piso_id;
$space->bedrooms = $request->bedrooms;
$space->bathrooms = $request->bathrooms;
$space->parking = $request->parking;
$space->area = $request->area;
$space->save();
$properti->spaces_id = $space->id;
foreach ($request->input('characteristic') as $characteristic) {
$charc = new Characteristic;
$charc->property_id = $piso_id;
$charc->characteristic = $characteristic;
$charc->save();
}
Session::flash('message', 'Se ha registrado su propiedad De forma exitosa');
return redirect()->action('PropertyController@index');
// return view('properties.index',compact('properties'));
}
Migration - Properties
public function up()
{
Schema::create('properties', function (Blueprint $table) {
$table->id();
$table->string('name')->nullable;
$table->string('price')->nullable;
$table->text('description')->nullable;
$table->unsignedBigInteger('property_type_id')->nullable();
$table->unsignedBigInteger('offer_type_id')->nullable();
$table->unsignedBigInteger('spaces_id')->nullable();
$table->unsignedBigInteger('departaments_id')->nullable();
$table->unsignedBigInteger('municipalities_id')->nullable();
$table->unsignedBigInteger('details_id')->nullable();
//$table->unsignedBigInteger('characteristics_id')->nullable();
$table->unsignedBigInteger('images_id')->nullable();
$table->decimal('lat', 8, 5)->nullable;
$table->decimal('lng', 8, 5)->nullable;
$table->string('address')->nullable;
$table->timestamps();
$table->foreign('property_type_id')->references('id')->on('property_type');
$table->foreign('offer_type_id')->references('id')->on('offer_type');
$table->foreign('spaces_id')->references('id')->on('spaces');
$table->foreign('departaments_id')->references('id')->on('departaments');
$table->foreign('municipalities_id')->references('id')->on('municipalities');
$table->foreign('details_id')->references('id')->on('details');
$table->foreign('images_id')->references('id')->on('images');
//$table->foreign('characteristics_id')->references('id')->on('characteristics')->onDelete('cascade');
});
}
Migration images
public function up()
{
Schema::create('images', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->unsignedBigInteger('property_id');
$table->timestamps();
});
}
my property model
public function Images()
{
return $this->hasMany('App\Image', 'images_id');
}
model images
class Image extends Model
{
protected $fillable = ['name', 'property_id'];
public function properties()
{
return $this->belongsTo('App\Properties');
}
}
I don't know if I have something wrong with my controller but it gives me the error before saving it
$imagesarray, and pushing$namevalues to it, but never using it beyond that.$properti->images = $request->images;its not a field, its a relationship withImagemodel