october cms: relations



This is a (hopefully correct) working example of a 1 to n relation.




install mongodb for php7

Forms with Laravel 5

Some components have been removed from Laravel core with version 5.

For example the Forms & HTML component.

Good to see them again here: https://laravelcollective.com

Example form:


Laravel Lumen: NotFoundHttpException after installation

After a fresh installation of Laravel Lumen, I got a NotFoundHttpException for the index route. I copied the .env.example  file to .env  and set up the APP_KEY. But I still got the NotFoundHttpException.

After searching the internet for some time I found out these steps:

In public/index.php change the last line to this:

And to make the .env  file working go to bootstrap/app.php  and uncomment the following line:




File upload by ajax with Laravel and jQuery

Some Controller method in Laravel 4.2, with some JSON responses:

Some jQuery code, which handles the form submit and the results of the upload. Additionally we have notifications for the user.


Call an Artisan Command from anywhere

Small note on how to call an Artisan Command from a Controller or somewhere else:


silex and the trailing slash

Wrong route definition:

Right route definition:

The .htaccess file:


Silex: routing to hostname

This is an example how to split your silex project by different hostnames.

Docs: http://silex.sensiolabs.org/api/Silex/Route.html#method_host

some Twig functions / helper

Template function to generate asset URLs

Usage like this:

And here is the Twig function:

Template function for reading session value with dot annotation

Access session values within the template like this:

And here is the Twig function:


Twig asset helper

This function generates an URL for project assets.


Here are other solutions:


persistent language prefixing with laravel

Here I want to describe how to build up a persistent language prefixing for your URLs in Laravel.

This technique requires, that the routes are named! This is just a quick sketch, and not fully complete!

In the app::before filter I detect the language. If no language was detected I redirect to the default language.

The Routes are working with a locale pattern. Here is an example:

In my global.php (e.g.) I put a new route() function and the function to do a language switch. The language switch changes just the current language but keeps the current page displayed.

eloquent: prevent duplicate rows

To prevent duplicate database entries there is a built-in method in Eloquent.

Overriding an implementation inside the IoC

This example overrides a model with your custom implementation.

Example 2:


PHP profiling with Xdebug

Best is to enable Xdebug with a trigger, that is added by a .htaccess. With this method I can profile a single application within my development environment.

Xdebug settings

To make use of Xdebug I need to add a GET, POST or COOKIE variable with the name XDEBUG_PROFILE.

I use a .htaccess in my project root to add the specified GET parameter.

.htaccess Example

 Analyzing the Output

On my Windows 7 maschine I use WinCacheGrind to analyze the profiler output.

Laravel: resolve the logged in user from the IoC container

Behind the scenes, the Auth facade is bound to Illuminate\Auth\AuthManager. Means, you need to resolve the AuthManager.

This example resolve the currently logged in user from the IoC container:

Link to reference:


PHP and MS Excel

There are several libraries out there for reading and writing MS Excel files. Here I note down my experiences with some of them.

Here is a list of libraries for working with Excel:



Link: https://packagist.org/packages/maatwebsite/excel

Reading a worksheets first column:

Be sure to configure the Package to import the headings as numeric:

Here is my sample code:



Link: https://packagist.org/packages/php-excel-reader/spreadsheet-reader

Reading a worksheets first column:


Export as HTML to Excel

Last but not least there is the HTML output. Here I found a nice article about: http://jwcooney.com/2011/09/08/generating-excel-documents-through-html-xml-and-css-part-2/

PHP Header

Example HTML Table


Transform a JSON string into a one dimensional array

The mission was to transform a JSON string into a one dimensional array. The array keys should contain the path to each JSON node.


The result

The result should be an array with the path of every JSON node and its value.