I am inserting the data to the rows one by one, but I have heard somewhere that it requires much time if there are many data to insert. So what are the ways of inserting the
public function add(Request $request) { if($request->ajax()) { $books=$request->books; $data = array(); foreach($books as $book) { if(!empty($book)) { $data[] =[ 'name' => $book, 'user_id' => Auth::id(), ]; }} Book::insert($data); }}
make sure imported use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Auth;