Try changing
$model = new IPMSAN($request->all());
$model->save();
to
$model = IPMSAN::create($request->all());
Whatever fields are in the $request must be $fillable on the model.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello Laracast community, I am using laravel as a back end but when i try to post someting i get an error : ARRAY TO STRING CONVERSION this is my add function:
public function addIPMSAN (Request $request)
{
$model = new IPMSAN($request->all());
$model->save();
$response = array ('response' =>'IPMSAN record successfully created with id !', 'success'=>true);
return $response ;
}
and this is my form in frontend i know the problem is from using date can i get some help here plz
IPMSAN/Central
<div class="form-group">
<label for="name_ipm" class="col-sm-4 control-label">Name</label>
<div class="col-sm-16">
<input type="text" class="form-control" name="name" [(ngModel)]="model.name_ipm" #name="ngModel">
</div>
<div *ngIf="name.errors && (name.dirty || name.touched)" class="alert alert-danger">
<div [hidden]="!name.Errors.required">
<span class="glyphicon glyphicon-exclamation-sign"></span> Name is Required
</div>
</div>
</div>
<hr>
<div class="form-group">
<label for="refrence" class="col-sm-4 control-label">Reference</label>
<div class="col-sm-16">
<input type="text" class="form-control" name="refrence" required [(ngModel)]="model.refrence_ipm" #refrence="ngModel">
</div>
<div *ngIf="refrence.errors && (refrence.dirty || refrence.touched)" class="alert alert-danger">
<div [hidden]="!refrence.Errors.required">
<span class="glyphicon glyphicon-exclamation-sign"></span> Refrence is Required
</div>
</div>
</div>
<hr>
<div class="form-group">
<label for="latitude" class="col-sm-4 control-label">Latitude</label>
<div class="col-sm-16">
<input type="text" class="form-control" name="latitude" required [(ngModel)]="model.latitude_ipm" #latitude="ngModel">
</div>
<div *ngIf="latitude.errors && (latitude.dirty || latitude.touched)" class="alert alert-danger">
<div [hidden]="!latitude.Errors.required">
<span class="glyphicon glyphicon-exclamation-sign"></span> latitude is Required </div>
</div>
</div>
<hr>
<div class="form-group">
<label for="longitude" class="col-sm-4 control-label">longitude</label>
<div class="col-sm-16">
<input type="text" class="form-control" name="longitude" required [(ngModel)]="model.longitude_ipm" #longitude="ngModel">
</div>
<div *ngIf="longitude.errors && (longitude.dirty || longitude.touched)" class="alert alert-danger">
<div [hidden]="!longitude.Errors.required">
<span class="glyphicon glyphicon-exclamation-sign"></span> longitude is Required </div>
</div>
</div>
<hr>
<div class="form-group">
<label for="deployment_date" class="col-sm-4 control-label">Deployment Date</label>
<form class="form-inline">
<div class="form-group">
<div class="input-group">
<input type="text" class="form-control" placeholder="yyyy-mm-dd" name="deployment_date" [(ngModel)]="model.deployment_date" ngbDatepicker #deployment_date="ngbDatepicker">
<div class="input-group-append">
<button class="btn btn-outline-secondary" (click)="deployment_date.toggle()" type="button">
<img src="assets/img/calendar.svg" style="width: 1.2rem; height: 1rem; cursor: pointer;" />
</button>
</div>
</div>
</div>
</form>
</div>
<hr/>
<div class="form-group">
<label for="maintenance" class="col-sm-4 control-label">Maintenance</label>
<form class="form-inline">
<div class="form-group">
<div class="input-group">
<input type="text" class="form-control" placeholder="yyyy-mm-dd" name="maintenance" [(ngModel)]="model.maintenance" ngbDatepicker #maintenance="ngbDatepicker">
<div class="input-group-append">
<button class="btn btn-outline-secondary" (click)="maintenance.toggle()" type="button">
<img src="assets/img/calendar.svg" style="width: 1.2rem; height: 1rem; cursor: pointer;" />
</button>
</div>
</div>
</div>
</form>
</div>
<hr>
<div class="form-group">
<div class="col-sm-offsset-4 col-sm_16">
<a class="btn btn-info" (click)="goBack()">Cancel</a>
<button type="submit" class="btn btn-success" id="btn-save" [disabled]="!addIPMSANForm.form.valid">submit</button>
<button class="btn btn-danger " (click)="addIPMSANForm.form.reset()"> Reset</button>
<div class="alert alert-success alert-dismissible" id="msg1" style="display: none;"></div>
</div>
</div>
</form>
Ok, in your controller, change
namespace App;
namespace App\Controller;
namespace App\Http\Controllers;
use App\Controller\AppController;
to just
namespace App\Http\Controllers;
In the controller, change
$model = \App\IPMSAN::create($request->all());
to
$model = IPMSAN::create($request->all());
These aren't laravel issues. They're basic php issues.
Please or to participate in this conversation.