Insert data into multiples tables - laravel

I have an excel file file that some data need to be inserted into Table1 and some other data into Table2 or Table3.
I Already have my routes,models, controllers for each table.
As I have to do one function to insert data into all tables, I don't know if I need to do it inside a Model. Also I don't know how to do it, how designate the right data to the right table.
Edit: More specific
I have a file input and a button inside my view. When I select the excel file with the input and press the button I need to read the data AND insert that data into my database. The problem here is that this data will go to different tables. I would know solve this if all data would go to a single table, but I have no idea how to divide the data to separte tables.
Should I call a function from controller inside the view ? If so which Controller use ? Or maybe a function from model, but again which Model should I use ? Since each table has it's own Model.
Do I need to use JQuery to make an Ajax then direct it to a certain route so that route would call a Controller's function that would make the inserts?
I Dont think so because all data manipulation should be inside a View, right ?

Related

Joomla: fetch data from table to include it into the link

Let's imagine we have a web-page with the content and one of the elements is table where we have couple of columns. It is done with Joomla, so basically I am working with the web-page constructor if I can call it like this and not with code. In the last column I have a link with query parameters, so something like this: link?qparam1=sth1&qparam2=sth. The values for these query parameters should be taken from the first and second column and inserted in this link. Otherwise I need manually to copy those values to each and every link which makes in very slow and inefficient especially when table values are changed, the link must be updated as well.
Is it possible to fetch the data from columns and include into the link?
Write a system plugin, Get data from a table, insert/update data to request
$app = JFactory::getApplication();
$app->input->set('qparam1','<value from table>');
it will update request data.

get last record ID after insert Joomla 3 component

I am writing a Joomla 3 component and new to the Joomla framework.
I need to insert data into two tables.
the logic follows
insert form data into table after submit
retrieve data for next insert ( i can do this and i have the data array )
insert data from array into second table with the PK of the first insert from step 1.These tables are related by 1-M
return the user back to where they came from with success.
I think i have to override the save method in my model to do this but i don't understand how to get the pk of the first save to use with the 2nd
Due to my lack of understanding I am not sure of best practice in this situation.
after reading there is a postSaveHook() method but I am do not understand how to access the data as it returns void
If i copy the Joomla parent save Method and override in the model it will return Boolean therefore i don't no how to access the last PK from the first insert / save.
thanks in advance for any advice.

Magento: Where would I place that functionality?

I have a Magento form with a button and some fields. The button click calls a controller and in the controller I query the DB (using fetchAll) and create a csv file from the results.
Whats the best place to store the DB action and the CSV file creation? In a model maybe?
Thanks!
I would create a model, a resource model and a resource model collection for the data you need to export. In the collection I would define functionality that queries data from one or many (if necessary) tables . In the model itself I would create a function that fetches that collection and saves it into a CSV file. The controller action would contain only the model initialization and a call to the export function.

problem with 'datatable' jquery plugin and two table (ajax related)

i have two tabs that their content loads by ajax. both have a table in their content. i want to apply 'datatable' jquery plugin to both table. tables have the same id because they are create by a function.but their rows are different.
datatable plugin is applied to first tab table well but on the second one give this error:
"DataTables warning (table id = 'dttable'): Cannot reinitialise DataTable.
To retrieve the DataTables object for this table, please pass either no arguments to the dataTable() function, or set bRetrieve to true. Alternatively, to destory the old table and create a new one, set bDestroy to true (note that a lot of changes to the configuration can be made through the API which is usually much faster)."
i use "bDestroy":true in datatable plugin define.but in this way the plugin doesn't show in second table.
would you help me?
Your problem is that both tables have the same ID, which is invalid HTML. When you try to initialize the second Databable, your selector only finds the first table and tries to initialize Datatables on the first table again, which results in the error that you are getting.
You need to change your function to create each table with a unique ID and initialize each table by its respective ID.
Why not set the Datatables by a className rather than ID then it can apply to both of them?
When retrieving the data you can use something like $('.dataTableStyle').eq(1) to get information from the relevant one.
I'm using mvc3 and my problem was with initializing a dataTable in a view, then rendering a partial view with another dataTable. The issue was not in the id's of the 2 tables, but in the way the partial views get rendered in the framework. In my case, I had to move the script, or reference to the script, into the view that hosts the partial view. I had an issue similar to this using the Google Maps api.
try this code
$(document).ready(function() {
oTable = $('#DataTables_Table_0').dataTable({ //DataTables_Table_0 <-------table id
iVote: -1, //your field name
"bRetrieve":true
});
oTable.fnSort( [ [1,'desc'] ] );
});
use this in function event when you would change your table data
$('#tbl_resultates').dataTable().fnDestroy();
and add
"bRetrieve": true,
in
$('#tbl_resultates').dataTable({

TableAdapter to return ONLY selected columns? (VS2008)

(VS2008) I'm trying to configure a TableAdapter in a Typed DataSet to return only a certain subset of columns from the main schema of the table on which it is based, but it always returns the entire schema (all columns) with blank values in the columns I have omitted.
The TableAdpater has the default Fill and GetData() methods that come from the wizard, which contain every column in the table, which is fine. I then added a new parameterized query method called GetActiveJobsByCustNo(CustNo), and I only included a few columns in the SQL query that I actually want to be in this table view.
But, again, it returns all the columns in the master table schema, with empty values for the columns I omitted.
The reason I am wanting this, is so I can just get a few columns back to use that table view with AutoGenerateColumns in an ASP.NET GridView. With it giving me back EVERY column i nthe schema, my presentation GridView contains way more columns that I want to show th user. And, I want to avoid have to declare the columns in the GridView.
When you add a new query to a given TableAdapter, it is going to assume the schema in which it is attached to, which is why you are getting blank values for the columns you don't want.
Since you mentioned having already created the procedure, what you need to do is use the Server Explorer to connect to the database and simply drag that stored procedure over into your XSD work area. What this will do is create a separate QueryAdapter that will have just the columns you specified (still strongly typed) and you can bind/interact with your GridView using that QueryAdapter instead.
Is the strongly typed dataset used in another query that returns all the rows from the table?
What you could do is create a dataview using the strongly typed dataset and expose a data table for your DataGridView.
I'm not sure what your requirements are totally, but this example should help you:
DataView dv = new DataView(ds.<Your_Table>);
// This will create a new data table with the same name,
// But with only two columns from the original table.
// This could then be bound to your data grid.
DataTable dt = dv.ToTable(false,
ds.<Your_Table>.<Your_Column1Column>.ColumnName,
ds.<Your_Table>.<Your_Column1Column>.ColumnName);
Just delete the columns you don't want at run-time before you bind to your Gridview. The underlying class is still just a DataTable after all.

Resources