Şu şekilde yazdım kodları
Controller Sayfası
` public function store(Request $request)
{
$article=new Article;
$article->marka=$request->marka;
$article->arac_id=$request->arac_id;
$article->model=$request->model;
$article->alt_model=$request->alt_model;
$article->yakit_tip=$request->yakit;
$article->vites=$request->vites;
$article->model_yil=$request->model_yil;
$article->renk=$request->renk;
$article->km=$request->km;
$article->sube_ad=$request->sube;
$article->il=$request->il;
if ($request->has('images')){
foreach ($request->file('images') as $image){
$imageName = $article['arac_id'].'-image-'.rand(1,1000).'.'.$image->extension();
$image->move(public_path('resimler'),$imageName);
Image::create([
'arac_id'=>$article->arac_id,
'image'=>$imageName
]);
}
}
toastr()->success('Data has been saved successfully!');
return redirect()->route('admin.makaleler.index');
}`
Create Sayfası
<form action="{{route('admin.makaleler.store')}}" method="post" enctype="multipart/form-data">
@csrf
<div class="form-group">
<label>Araç Resim</label>
<input type="file" name="image[]" class="form-control" accept="image/*" multiple required>
</div></form>
Controller Sayfasının Model Sayfası
`<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use PhpParser\Node\Expr\AssignOp\Mod;
class Article extends Model
{
use HasFactory;
protected $guarded = [];
public function images(){
return $this->hasMany(Image::class);
}
}
`
Image Model Sayfası
`<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Image extends Model
{
use HasFactory;
protected $guarded = [];
}
`
Bu kodlar ile şu an çalışıyor ama veritabanına kaydetmiyor.