hello im trying to save my filename in database laravel , but it gives me im doing upload image with laravel. The image is uploaded yet the field from my rent database not. This is what happens.
Creating default object from empty value
im using Storage:link
Controller use Illuminate\\Http\\Request; use Illuminate\\Support\\Facades\\Storage;
public function insertproof(Request $request)
$id = $request['id'];
if ($request->hasFile('rent_proof')){
$filepath = $request->file('rent_proof')->store('app/folder_proof');
}
$result = rent::find($id);
$result->rent_proof=$filepath;
$result->save();
}
and here is my view and this view is from mymodal
<form method="POST" action="{{route('visitor_rent.insertproof')}}"
enctype="multipart/form-data">
{{ csrf_field() }}
<div class="form-group">
<input type="file" class="form-control" name="rent_proof" id="proof">
</div>
<button type="submit" class="btn btn-success">Save</button>
</form>
This is my model
public class Rent extends Model
{
protected $primaryKey = 'id';
protected $fillable = ['rent_proof'];
}
edit : hello this one that gives me the error
$result = rent::find($id);
$result->rent_proof=$filepath; //<--this line is giving me the error
$result->save();
thanks for the care is there anything that i miss?
Version laravel 5.5 PHP 7.2
Creating default object from empty value
this error is because id which you have passed doesn't exists in your database.
if you are creating a new record with id and image path
then you should use
$result = new Rent;
$result->rent_proof=$filepath; //<--this line is giving me the error
$result->save();
If you are updating existed one then pass proper id which exists in database
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.