Hier is je antw. Je gaat goed op weg, je hebt een draaitabel voor klant en project gemaakt, zodat je zoveel projecten aan elke klant kunt koppelen. Hier is de relatie met het model.
Klantmodel
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Client extends Model
{
public function projects() {
return $this->belongsToMany(Project::class,'client_project');
}
}
Projectmodel
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Projects extends Model
{
public function client() {
return $this->belongsToMany(Client::class,'client_project');
}
}
?>
Gebruik de volgende manier om de project-ID op te slaan in de controllermethode
$client = new Client();
$client->name = $request->input("nameClient");
$client->slug = $request->input("slugClient");
$client->priority = $request->input("priorityClient");
$client->save();
$project = new Project();
//include fields as per your table
$project->save();
$client->projects()->attach($project->id);
.