Created
June 28, 2017 03:09
-
-
Save browner12/01167424b98c7cd12c3187cfdc18bef7 to your computer and use it in GitHub Desktop.
Polymorphic Model Builder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Controller | |
{ | |
public function index(Request $request) | |
{ | |
$taggable = model($request->get('taggable_type'), $request->get('taggable_id'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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