Select and generate insert statement from database with laravel coding

Hello there hope you will doing well. I want to select table records and then generate insert statements from that selected tables and save those insert statements in a text file how i can get this in laravel I have search alot but could not find any solution.Please help me.

Thanks in advance.

Blade code.

<form  id="tblExportsForm" autocomplete="off">

<fieldset>
<legend>Database Export Synchronization</legend>
<div class="form-group">
<label class="cus-label">Select Table(s) <span class="badge badge-success circle"></span></label>
<select name="tblExportSelect[]" id="tblExportSelect" class="form-control" required multiple>
<option value="">Select an option</option>
@foreach($tables as $key => $table)
<option value="" data-id = ""></option>
@endforeach
</select>
</div>
<div class="form-group btn-toggle">
<button type="submit" id="BtnSubmit" class="btn btn-primary" style="letter-spacing: 2px;"><i class="fas fa-sync-alt"></i> Export Data </button>
</div>
</fieldset>
<div id="loader"></div>
</form>

Blade Javascript

$('#BtnSubmit').on('click',function(){
$("form#tblExportsForm").validate({
errorElement:'span',
errorClass:'help-block pull-left err',
ignore:":hidden:not(select)",
debug:true,
rules:{
tblExportSelect:{
required:true
},
},
highlight:function(element){
$(element).closest('.form-group').addClass('has-error');
},
errorPlacement: function (error, element) {
if(element.hasClass('select2') && element.next('.select2-container').length) {
error.insertAfter(element.next('.select2-container'));
}
else if (element.parent('.form-group').length) {
error.insertAfter(element.parent());
}
else {
error.insertAfter(element);
}
},
success:function(label){
label.closest('.form-group').removeClass('has-error');label.remove();
},
invalidHandler:function(form,validator){
if(!validator.numberOfInvalids())return;
},
messages:{

},
submitHandler:function(form,e){
var btn=document.querySelector("#BtnSubmit");
btn.style.display="none";var img=document.createElement("img");
img.setAttribute("src",base_url+'front/images/loading.gif');
var loader=document.querySelector("#loader");loader.appendChild(img);
var url="<?php echo route('database.export-txtProcess');?>";
var cur_url="<?php echo route('database.export-txt');?>";

//var tblExportSelect = $("#tblExportSelect").val();


var pushArray = [];
$.each($("#tblExportSelect option:selected"), function(){
pushArray.push($(this).data("id"));
});

var data = new FormData();

data.append('tblExportSelect',pushArray);


//$("#tblExportSelect").val(selected);


axios({
method: 'POST',
url: url,
data: data
})
.then(function(res){
// console.log(res);
})
e.preventDefault();
}
});
});

Controller Method

public function exportTxtProcess(Request $request){

/*dd($request->tblExportSelect);*/

$tables = explode(",", $request->tblExportSelect);

foreach ($tables as $table) {
$output = DB::statement("SELECT * FROM $table");

print_r($output);
}
}

from Newest questions tagged laravel-5 – Stack Overflow https://ift.tt/37Z2nLs
via IFTTT

Related Posts

Codeigniter : Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE) in Laravel project

I’m getting following error: **Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE)** Note : It’s working in local but facing issue in production server. private…

Firebase receive notification while tab is active or on focus

What i want is to be able to perform an action when a user receives a notification while the browser is open and tab is active or…

Laravel’s alias loader does not find class

We have a legacy project that we cannot update and we need to make some changes in symfony’s Response.php in vendor. We have solved this by copying…

Laravel 5 – generic document management

I have a system where you can create different types of unique documents. For instance, one document is called Project Identified and this expects certain inputs. Originally,…

Laravel Nova limit the results in indexQuery

I ran intro a situation where I need to limit the results of a resource to only 3 results. To be more specific, based on the logged…

Auditoria en laravel 5.8 [closed]

Cómo puedo automatizar el registro de actividades de un usuario en laravel? Si un usuario ingresa a un app de laravel, debo guardar toda su actividas, a…

Leave a Reply

Your email address will not be published.