Nicho Posted December 9, 2022 Share Posted December 9, 2022 (edited) Hello, i'm currently developing a website using laravel. I have added a 3 new columns for bravo_book_others table the columns are other_name, gender, and other_address. I have a case like this : User1 want to buy 4 holiday package for user1 friends, so user1 have to input 3 of user1 friends like this : Gender#1 : male Name#1 : a Email#1 : a@gmail.com Address#1 : a street Gender#2 : female Name#2 : b Email#2 : b@gmail.com Address#2 : b street Gender#3 : male Name#3 : c Email#3 : c@gmail.com Address#3 : c street I already done it with the email in the controller like this : foreach ($request->input('other_emails') as $email){ BookOther::create([ 'booking_id'=>$booking->id, 'user_id'=>$booking->customer_id, 'other_emails'=>$email ]); Mail::to($email)->send(new OthersEmail($isi_email1)); } How can i put the other_name, gender, and other_address and store it into the database?? The Model : class BookOther extends Model { use HasFactory; protected $table = 'bravo_book_others'; protected $fillable = [ 'booking_id', 'user_id', 'gender', 'other_name', 'other_address', 'other_emails' ]; public function booking(){ return $this->belongsTo('Modules\Booking\Models\Booking', 'booking_id', 'id'); } public function user(){ return $this->belongsTo('App\User', 'user_id', 'id'); } } The Controller : foreach ($request->input('other_emails') as $email){ BookOther::create([ 'booking_id'=>$booking->id, 'user_id'=>$booking->customer_id, 'other_emails'=>$email ]); Mail::to($email)->send(new OthersEmail($isi_email1)); } Edited December 9, 2022 by Nicho Quote Link to comment https://forums.phpfreaks.com/topic/315628-how-to-input-2-different-request-input-in-foreach/ Share on other sites More sharing options...
requinix Posted December 9, 2022 Share Posted December 9, 2022 Unless I'm missing something, you need to add the values for the new columns into the ::create array. And presumably those values are somewhere in the $request. Quote Link to comment https://forums.phpfreaks.com/topic/315628-how-to-input-2-different-request-input-in-foreach/#findComment-1603393 Share on other sites More sharing options...
maxxd Posted December 9, 2022 Share Posted December 9, 2022 (edited) I read the question wrong; please ignore me. Edited December 9, 2022 by maxxd Quote Link to comment https://forums.phpfreaks.com/topic/315628-how-to-input-2-different-request-input-in-foreach/#findComment-1603406 Share on other sites More sharing options...
Nicho Posted December 12, 2022 Author Share Posted December 12, 2022 On 12/10/2022 at 1:30 AM, requinix said: Unless I'm missing something, you need to add the values for the new columns into the ::create array. And presumably those values are somewhere in the $request. I already try it like this foreach foreach ($request->input('other_emails') as $email){ BookOther::create([ 'booking_id'=>$booking->id, 'user_id'=>$booking->customer_id, 'other_name'=>$request->input('other_name'), 'other_emails'=>$email ]); Mail::to($email)->send(new OthersEmail($isi_email1)); } But the output will be likt this : input : Name : a Email : a@gmail.com Name : b Email : b@gmail.com Output : Name : b Email : a@gmail.com Name : b Email : b@gmail.com Quote Link to comment https://forums.phpfreaks.com/topic/315628-how-to-input-2-different-request-input-in-foreach/#findComment-1603461 Share on other sites More sharing options...
requinix Posted December 12, 2022 Share Posted December 12, 2022 You have more than one other_emails. Don't you have more than one other_name too? Quote Link to comment https://forums.phpfreaks.com/topic/315628-how-to-input-2-different-request-input-in-foreach/#findComment-1603463 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.