PHP

Cloning Eloquent Models in Laravel

Duplicating an Eloquent model — without its primary key, without timestamps, without accidentally overwriting the original record — is a small problem with a few subtly wrong solutions before you arrive at the right one.


The clone keyword

PHP has a built-in clone keyword that produces a shallow copy of an object. Scalar properties are copied by value; object properties are copied by reference. For a database model, the defaults are almost never right: the copy shares the same id, its exists flag is still true, and any object-type properties point to the same instances as the original.

Read more →

Joomla 1.5 Component with Jquery and Mootools

I’ve been building a component for Joomla 1.5 and I really wanted to use Jquery in the admin over Mootools. Unfortunately Googling for this answer is tricky as so many people are posting examples how to remove Joomla js from their frontend template. The following is very ‘hacky’ but if you’re feed up with the Joomla API and want to throw together a component, without mootools, it’s useful. It stops the need to export jQuery into a different name space, therefore breaking 3rd party jQuery plugins.

Read more →