Skip to content

Instantly share code, notes, and snippets.

@browner12
Created June 28, 2017 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save browner12/01167424b98c7cd12c3187cfdc18bef7 to your computer and use it in GitHub Desktop.
Save browner12/01167424b98c7cd12c3187cfdc18bef7 to your computer and use it in GitHub Desktop.
Polymorphic Model Builder
class Controller
{
public function index(Request $request)
{
$taggable = model($request->get('taggable_type'), $request->get('taggable_id');
}
}
<?php
function model($type, $id)
{
return (new $type)::find($id);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment