Skip to content

Instantly share code, notes, and snippets.

View dave-mills's full-sized avatar

Dave Mills dave-mills

View GitHub Profile
@shanginn
shanginn / README.md
Last active August 8, 2024 13:40
Get available relationships trait for Eloquent model (Laravel 5.*)

GetRelationships Trait

This trait will allow you to get defined relationships on the model. I wish Laravel have a way to get this without any additions(except for trait), but there is no way.

Here we have 2 versions of the trait: for PHP7 and for PHP5.

Both method uses Reflections to collect information about the model.

PHP7

With PHP7 version you'll only need to add return class for the relationship method like this:

@brenna
brenna / wp-autopopulate-taxonomy
Last active December 26, 2022 23:29
WordPress function to auto-populate a taxonomy with a custom post type's entries.
function custom_tax_init(){
//set some options for our new custom taxonomy
$args = array(
'label' => __( 'My Custom Taxonomy' ),
'hierarchical' => true,
'capabilities' => array(
// allow anyone editing posts to assign terms
'assign_terms' => 'edit_posts',
/* but you probably don't want anyone