Datensatz-Sammlungs-Paket

Introduction

This is the package I use for my Record Collection on this site. It provides a searchable HTML interface, an API interface and an administrative interface.


Installation

composer require escuccim/recordcollection

Then register the components in /config/app.php:

Add the following to the 'providers' array:

Escuccim\RecordCollection\RecordCollectionServiceProvider::class,
Laracasts\Flash\FlashServiceProvider::class,

And add the following to 'aliases' array:

Run the database migrations to create the blog tables and update the users table:

php artisan migrate

To enable the JavaScript features of the search page pages you need to add the following to the head of your layouts/app.blade.php view:

<script src="/js/app.js"></script>
@stack('scripts')

Note that you must move the script tag referencing app.js from the bottom of the layout to the header to enable the Javascript features of the search and administrative screens.

You must publish the pagination and config files with:

php artisan vendor:publish --tag=config

This will publish the Javascript files used for the search page to your public directory and will place altered pagination files in your resources directory. These are all required for the search interface to function properly.

By default I use a middleware I call 'admin' to verify if the user has permission to access the administrative pages. If you wish to use this you need to register the middleware in /app/Http/Kernel.php in $routeMiddleware:

'admin' => \Escuccim\RecordCollection\Middleware\AdminMiddleware::class,

If you wish to use your own middleware or stick with Laravel's Auth middleware you can do so by updating the config (see below).


Usage

This package contains its own routes, models, controllers and views so should work after installation. To access it just go to /records.

If you wish to edit my views or other files you can publish them to your application:

php artisan vendor:publish

This will publish all of the files. To only publish certain files add --tag=[group], using the groups listed below:

  • config - publishes the config file to /config/records.php as well as publishing other necessary files.
  • views - publishes the views to /resources/views/vendor/records
  • lang - publishes the language files to /resources/lang/vendor/record-lang
  • migrations - published the migration files to /database/migrations

You must publish the config group of files for the search interface to work properly. The config group includes the JavaScript files used by the search interface, and customized pagination files.

To add additional languages, publish the lang files and then create new directories under /resources/lang/vendor/record-lang corresponding to the language you wish to add. Copy the records.php file into your new directory and put the translations into the new language into the array.

Note that out of the box the blog will use the languages specified in config/app.php under 'locale'. If you wish to have the blog translate on a per request basis you will need to provide the code for this, or use my package escuccim/translate.


Configuration

To access the configuration files you need to publish the config file to /config/blog.php with

php artisan vendor:publish --tag=config.

The config file has the following values:

  • table_name - the table name used by the models. This defaults to records_new because I have another table named records in my database.
  • results_per_page - the number of results displayed per page in the HTML interface, defaults to 23.
  • middleware - the middleware used to determine if the user has permission to access administrative pages. Defaults to my admin middleware, if you want to use Laravel's auth replaced this with 'auth' or you can use your own middleware.
  • is_user_admin - function used to determine whether to display administrative buttons like add, edit and delete. If you are not using my middleware replace this with the name of a function which returns true if the user is an administrator and false otherwise.
  • use_rich_card - this allows you to include a rich card in the record detail page.