How can i delete multiple row using laravel excel - excel

I have a table with id,details.Field 'details' contain single family member details like name,age,dob etc.
table like,
|id|details|
|---|---|
|1|{'name':'john','age':'12','dob':'19-06-1987','address':'address','family_id':"1"}|
I want to delete multiple user details using excel file and data in details column (Id should not given).the excel file contain 3 column name,family_id (unique with each family),dob.i need to check those 3 field match with details column and delete the row.
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\Importable;
use Maatwebsite\Excel\Concerns\WithValidation;
class ImportDeleteFile implements ToModel, WithValidation
{
use Importable;
public function rules(): array
{
return [
//what i do here
];
}

Related

How to remove duplicate rows from excel import in Laravel

I am importing an excel file in Laravel 7 that contains employees' records. The file has Columns Employee No. and date. There are duplicate rows that contain the same employee No. and date. I want to store only 1 such record and discard the duplicate rows. Is there any way to do so?
If you're using laravel-excel, you can define rules for validation and check for duplicate records.
In below example, I've checked for duplication for user with email address.
class ModelImport implements ToModel, WithValidation
{
public function rules(): array
{
return [
'1' => \Illuminate\Validation\Rule::unique('users', 'email'),
];
}
}
Then, add skipping errors by implementing Maatwebsite\Excel\Concerns\SkipsOnFailure interface as stated in here
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Validators\Failure;
use Maatwebsite\Excel\Concerns\Importable;
use Maatwebsite\Excel\Concerns\SkipsOnFailure;
use Maatwebsite\Excel\Concerns\WithValidation;
class ModelImport implements ToModel, WithValidation, SkipsOnFailure
{
use Importable, SkipsFailures;
}

How to select data from excel sheet categorically in Flutter

I am a beginner in Flutter, I have a database of product items in a General Store in Excel file. I want to select the data from the excel database using their categories(the database has a column of categories)(such as Medicine or Automobile Items). Then I want to use the data in form of cards to show customers the product image and info. Please suggest me to how to select the data from an excel file (like ordering the data as per some condition).
WorkAround - I thought of converting .xlsx to .csv then to .json file and then finally storing it in Firebase which is the database I am currently using in my project. But the problem with that would be, the download usage would increase which would lead me to cost money.
You can create a class to store the data of your items. Then hard code items into a file and use that file to look up in your application.
For example;
// Data Structre
class Item {
int id;
String category;
Item({this.id, this.category});
}
// Hard coded data storage
List<Item> items = [Item(id: 1, category: 'Medicine'), Item(id: 2, category: 'Automobile')];
// Methods to fetch data
List<Item> getItemsByCategory(String category) {
return items.where((item) => item.category == category).toList();
}

Laravel excel export list in list object maatwebsite/Laravel-Excel

Hi I want to export list of people with all theirs childrens in them to excel. I'm using maatwebsite/Laravel-Excel plugin and its quite easy to export users collection but I need to include users every children inside that row. Its something like [{Name, Age, Gender, Job, Children[{name, age, gender, etc...}], Birthday, etc...}]. And how do I change order of the data column displayed on excel like if I want to switch datas on Age and Gender. Thank you!
You can use WithMapping
https://docs.laravel-excel.com/3.1/exports/mapping.html
<?php
public function map($user): array
{
//create initial array with user data in order that you want columns to be
$data = [
$user->name
...
];
// the same way you should crate headers (if you have). But instead of values you should create column name
foreach($user->children as $child){
array_push($data, $child->name, $child->birthday, $child->...., ..., ...); //and so on
}
// returned data should be 1 level array as each item is a row in the table
return $data;
}

In pentaho dashboard how to display the table component columns using different sql datasources

I want to display a table with data coming from different sql tables, like for a single table component, some columns of the table come from one sql query and other column from next query. Using join queries or sub queries will display wrong data. In table component there is only one option for selecting the data-source.
Is there any way to do this?
With Javascript, in the pre-Execution function of the table component, you can change the datasource, but not for single columns.
You can hide some columns in the table component if you want.
How to change the datasource with Javascript
I created a Simple Parameter: refresh_table, and it contains the datasource of the table: sql_Empty, to show an empty table.
I created some Select components and when you choose a value and then you click on the Button component (a search button), the search button changes the value in the simple parameter 'refresh_table' with a new datasource based on the value in the select component: sql_A, sql_B.
function a() {
var a = this.dashboard.getParameterValue('selectA');
var b = this.dashboard.getParameterValue('selectB');
if (a === 'ciao' && b === 'ciao') {
this.dashboard.fireChange('refresh_table', 'sql_A');
} else {
this.dashboard.fireChange('refresh_table', 'sql_B');
}
}
In the preExecution function of the table component, I wrote this function to change the datasource based on the parameter value of refresh_table.
function b() {
this.chartDefinition.dataSource = this.dashboard.getParameterValue('refresh_table');
}
I think you can do it with Pentaho Data Integration/Kettle/Spoon and then you can pass the results to the table component, but I don't know how.

SubSonic 3 / ActiveRecord - Easy way to compare two records?

With SubSonic 3 / ActiveRecord, is there an easy way to compare two records without having to compare each column by column. For example, I'd like a function that does something like this (without having to write a custom comparer for each table in my database):
public partial class MyTable
{
public IList<SubSonic.Schema.IColumn> Compare(MyTable m)
{
IList<SubSonic.Schema.IColumn> columnsThatDontMatch = new...;
if (this.Field1 != m.Field1)
{
columnsThatDontMatch.add(Field1_Column);
}
if (this.Field2 != m.Field2)
{
columnsThatDontMatch.add(Field2_Column);
}
...
return columnsThatDontMatch;
}
}
In the end, what I really need is a function that tests for equality between two rows, excluding the primary key columns. The pseudo-code above is a more general form of this. I believe that once I get the columns that don't match, I'll be able to check if any of the columns are primary key fields.
I've looked through Columns property without finding anything that I can use. Ideally, the solution would be something I can toss in the t4 file and generate for all my tables in the database.
The best way, if using SQL Server as your backend as this can be auto populated, is to create a derived column that has a definition that uses CHECKSUM to hash the values of "selected" columns to form a uniqueness outside of the primary key.
EDIT: if you are not using SQL Server then this hashing will need to be done in code as you save, edit the row.

Resources