Ok, please take a look at this:
public function up()
{
Schema::create('images', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->unsignedBigInteger('post_id');
$table->timestamps();
$table->foreign('post_id')
->references('id')
->on('faro_posts')
->onDelete('cascade');
});
}
I have removed the images validation, is that fine? it's not a required field so.. and the relationship has been renamed accordingly
I still get an error and I can't remember how to fix it, is when you are trying to use a different name for a column but since Laravel will auto-name columns regarding the table name, for example since my table is named "faro_posts" it's trying to find "faro_id" but im using "post_id":
public function post()
{
return $this->belongsTo(Faro::class, 'post_id');
}
Just removing that error and then I will be able to test store(), this is how it's looking so far.
public function store(Request $request)
{
$post = request()->validate([
'title' => ['required', 'max:255'],
'body' => ['required'],
'category_id' => ['required']
]);
$postObject = Faro::create($post);
if($request->hasFile('images')) {
foreach($request->file('images') as $image) {
$postObject->images()->create(['image_url' => $image->store('faro_posts_img')]);
}
}
$postObject->save();
return redirect('/faro');
}