Laravel Object Clone

Posted by Alexis on 17 October 2012 | 0 Comments

Tags:

 

        public function __clone() {
            $clone = new self($this->to_array());
            unset( $clone->id );
            $clone->exists = false;
            return $clone;
        }

 Nice little laravel clone function. Extending the base elquent model for your self is generally best practice.

Then you can whack function little helper functions in there like this.

      public function __clone() {

            $clone = new self($this->to_array());

            unset( $clone->id );

            $clone->exists = false;

            return $clone;

        }


Post your comment

Comments

No one has commented on this page yet.

RSS feed for comments on this page | RSS feed for all comments