I'm asking you because I can't solve my problem.
file upload no problem but db insert is error
my blade code
<form action="{{ route('admin_multiupload_store') }}" method="POST" enctype="multipart/form-data" id="image-upload">
@csrf
<input type="hidden" name="type" value="{{ $type }}">
<input type="hidden" name="id" value="{{ $id }}">
</form>
my javascript code
<script type="text/javascript">
new Dropzone("#image-upload", {
maxFilesize:12,
acceptedFiles:".jpeg,.jpg,.png,.gif,.svg",
addRemoveLink:true,
timeout: 5000,
success: function(file, response){
Swal.fire({
icon: 'success',
title: 'İşlem Başarılı...',
text: '{!! session()->get('success') !!}'
});
},
error: function(file, response){
return false;
}
})
</script>
my controller code
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use app\Models\MultiImageModel;
class MultiImageController extends Controller
{
public function index($type, $id) {
return view('admin.multiupload', compact('type','id'));
}
public function store(Request $request) {
$image = $request->file('file');
$imageName = time().rand(1,1000).'.'.$image->extension();
$image->move(public_path('uploads/'),$imageName);
$image_data = new MultiImageModel();
var_dump($image_data);
$image_data->upload_type = $request->type;
$image_data->upload_id = $request->id;
$image_data->upload_filephp = $imageName;
$image_data->save();
return response()->json(['success'=> $imageName]);
}
}
model code
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class MultiImageModel extends Model
{
protected $table = 'multi_image_models';
use HasFactory;
}
the error i encountered enter image description here
Waiting for your replies, thanks :)
uploading the file to the directory and saving it to the database, but I can't save it to the database. only file upload is successful
CodePudding user response:
In the statement where you import the model class, capital letter "App" in the controller