0
I am trying to enter the data of a form of a class Condominium with the user already logged in and authenticated , user_id is foreign key to the table Condominium, in my understanding the store method should already bring the user_id in the array to insert the data but this is not happening, and because of this generates an SQL error saying that the user_id field cannot be null (because it is a foreign key as said). Follow the create and store method of the Condominium:
public function create()
{
$condominio = auth()->user()->condominio;
//$condominio = Condominios::create()->get();
$title='Cadastrar Condominio';
return view('admin.condominio.create',compact('title'));
}
public function store(Request $request)
{
$condominio = auth()->user()->condominio;
//dd($request->all());
Condominios::create($request->all());
return redirect()->route('admin.condominio.index')->with('message', 'condominio criado com sucesso!');
Keeps making the same mistake
– fabaoanalista
edited the answer
– David Santos
David in the fillable array I can not insert user_id because it is not an input field for user , earlier had managed doing this way but is ganbiarra, I have to get by going through the same Auth , I know it is possible.
– fabaoanalista
This is not gambiarra, it’s the way the framework works. If you want to do otherwise you will have to instantiate the model and set the attributes 1 by 1 and at the end of a $model->save()
– David Santos