1
I have a situation as follows. I have 4 user tables -> department -> categoria_department -> category -> posts Where in my view I have a select where it shows a data relation on ex department:
That information is coming from the database. I also have another select for the category see an ex:
So when I go to register the Article, it has to save this information in the pivot table that in the case is categorie_departamento. This table makes Manytomany relationship with the Departments and Category tables.
In my code it’s like this:
$departamento = new Departamento();
$categoria = new Categoria();
$postagem = new Postagem();
$findCat = $categoria->where('id' , $request->categoria)->get()->first();
$findDep = $departamento->where('id' , $request->departamento)->get()->first();
$findCat->departamentos()->attach([
'departamento_id' => $findDep->id,
'categoria_id' => $findCat->id,
]);
$postagem->categoria_id = $request->categoria;
$postagem->titulo = $request->titulo;
$postagem->imagem = $filename;
$postagem->descricao = $request->descricao;
$postagem->status = $request->status;
$result = $postagem->save();
So far so good. more it is saving the right id in the field ta pivot table right more later it writes one more line see:
What can that be?
Another thing if there is an easier way to do they can say why I have never made a posting system in my life.
Table picture the last 4 table images are the ones I want
The answer didn’t work?
– novic