Answer the question
In order to leave comments, you need to log in
How to insert data into database in controller?
Good afternoon, ladies and gentlemen.
There is a form implementation and I want to catch the data that is in it and throw it into the database. In order to monitor everything that happens in the admin panel.
I do not fully understand how this can be done in this situation.
My sketches:
public function postContact(Request $request) {
$this->validate($request, [
'email' => 'required|email',
'subject' => 'min:3',
'message' => 'min:10',
'infoaboutsender' => 'min:6']);
$data = array(
'email' => $request->email,
'subject' => $request->subject,
'bodyMessage' => $request->message,
'infoaboutsender' => $request->infoaboutsender,
'emails' => $request->emails
);
Mail::send('includes.contactemail', $data, function($message) use ($data){
$message->from($data['email']);
foreach ($data['emails'] as $selectedOption)
{
$message->to($selectedOption);
Feedback::insert('feedback')->insert([
'name' => $data['infoaboutsender'],
'email' => $data['email'],
'subject' => $data['subject'],
'message' => $data['bodyMessage'],
'employees' => $selectedOption,
]);
}
$message->subject($data['subject']);
});
FatalThrowableError in Builder.php line 2087:
Type error: Argument 1 passed to Illuminate\Database\Query\Builder::insert() must be of the type array, string given, called in
Answer the question
In order to leave comments, you need to log in
Try like this:
\DB::table('feedback')->insert([
[
'name' => $data['infoaboutsender'],
'email' => $data['email'],
'subject' => $data['subject'],
'message' => $data['bodyMessage'],
'employees' => $selectedOption,
]
]);
Documentation, read the documentation...
Feedback::create([
// массив с данными
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question