Download the PHP package flatmodel/laravel-csv-flatmodel without Composer

On this page you can find all versions of the php package flatmodel/laravel-csv-flatmodel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-csv-flatmodel

FlatModel CSV is an Eloquent-inspired data modeling system for Laravel that works with CSV files.

It provides an expressive, familiar API for reading and writing flat data sources without relying on a database.

Installation

Install with Composer into a new or existing Laravel project

Usage

A new CSV model can be made by running the artisan command which will prompt for a few details.

If instead you want to skip the prompts, the arguments can be provided instead;

Providing a primary key is optional and can be skipped with the --noprimary flag or by leaving the prompt empty when prompted for a primary key.

Once the model is generated, it can be used similarly to standard models within Laravel

The methods are returned as instances of the Illuminate\Support\Collection class that those familiar with Laravel will be comfortable with. This also means that working with the data returned is simple and straightforward.

Opt-in Features

FlatModel uses traits to provide optional functionality. Include these traits in your model as needed:

Writable

Enables write operations (insert, update, delete, upsert):

Backupable

Creates automatic timestamped backups before modifications:

AppendOnly

Restricts models to insert-only operations (no updates or deletes):

Note: AppendOnly requires the Writable trait since it restricts write operations.

HeaderAware

Enables strict header validation and provides header utility methods:

Strict mode behavior:

Without HeaderAware:

Type Casting

CSV files store all data as strings. Use the $cast property to automatically convert values to specific types:

Supported cast types:

Type casting is applied automatically when:

Working with Headerless CSV Files

If your CSV file doesn't have a header row, set $hasHeaders = false:

Option 1: Provide custom column names

Option 2: Use numeric indices

Header Row vs No Header Row

Query Methods

For interacting and querying data from the model, the following are available:

The model has a series of configurable properties that will enable or disable functionality.

Property Type Description Default
$path string The path of the file
$delimiter string The delimiter used within the file ,
$enclosure string The enclosure character used to wrap field values in the file "
$escape string The escape character used in the file \
$stream boolean Indicates whether the model operates in stream mode false
$headers array Array of column headers from the CSV file, if not provided will try to autodetect from file []
$hasHeaders boolean Indicates whether the CSV file has a header row. If true, the first row is treated as column names. If false, data starts from the first row. true
$strictHeaders boolean Enables or disables strict header checking false
$cast array Defines type casting rules for columns. Valid cast types are int, float, bool and string []
$writable boolean Indicates whether the model is writable, if true the model can be used to write data back to the file. If false, the model is read-only false
$appendOnly boolean Indicates whether the model is append-only. If true the model will only have data added to the end of the file, updates cannot be written to models configured for append-only false
$enableBackup boolean Enables or disables automatic backups on modification of the file false
$autoFlush boolean Indicates whether the model should flush the data to the CSV file on every modification false

[!IMPORTANT] If $autoFlush is set to false (as it is by default), flush() should be manually called to persist the data to the file.

Writing, Mutating & Flushing Data

Writable models can be modified and saved back to the file using flush() or save() if $autoFlush is disabled by using false.

Updates and deletes are also possible using similarly named methods using functional filtering.

Models can also be updated using more familiar array-based syntax.

[!WARNING] Models in stream mode cannot be written back to the file and are read-only. If an attempt is made to write to a model implementing stream mode, a StreamWriteException will be thrown.

[!WARNING] If the model is in append-only mode, updates, upserts and deletes will throw an AppendOnlyViolationException exception.

Exception Handling

FlatModel uses custom exceptions to provide clear and understandable error context all extending a common base of FlatModelException.

Exception Description
AppendOnlyViolationException When updating or deleting a model flagged as append-only
BackupFailedException When a backup fails prior to committing any changes to the file
CastingException When a type casting operation fails for a column value
ColumnNotFoundException When attempting to access a column that doesn't exist in the CSV
FileNotFoundException When the specified CSV file cannot be found
FileWriteException When writing changes to the CSV file fails
HeaderMismatchException When headers don't match expected values in strict mode
InvalidHandleException When attempting to read or write to an invalid file handle
InvalidRowFormatException When a row doesn't match the expected format
MissingHeaderException When required headers are missing from the CSV
PrimaryKeyMissingException When a primary key operation is attempted without a defined key
StreamOpenException When opening the CSV file in stream mode fails
StreamWriteException When attempting to write to a model in stream mode
WriteNotAllowedException When attempting to write to a read-only model

Testing

Run tests using Composer:

Or run PHPUnit directly:

License

FlatModel is open-sourced software licensed under the MIT license.


All versions of laravel-csv-flatmodel with dependencies

PHP Build Version
Package Version
Requires illuminate/collections Version ^12.14
illuminate/support Version ^12.14
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package flatmodel/laravel-csv-flatmodel contains the following files

Loading the files please wait ...