Last active
June 5, 2016 23:55
-
-
Save JordanDalton/332ae41831c17235106b to your computer and use it in GitHub Desktop.
Here's a simple, real-world example of implementation and extension of models and presenters.
This file contains 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 namespace Acme\Core; | |
use Eloquent; | |
class Model extends Eloquent {} |
This file contains 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 namespace Acme\Core; | |
use McCool\LaravelAutoPresenter\PresenterInterface; | |
class PresentableModel extends Model implements PresenterInterface { | |
/** | |
* Return the class name for our presenter. By default this will | |
* look for a presenter class based of the name of the model. You can override | |
* this in the model you create. | |
* | |
* Example: Acme\Reports\Report.php would use Acme\Reports\ReportPresenter.php | |
* | |
* @return string | |
*/ | |
public function getPresenter() | |
{ | |
// Return the presenter class name. | |
// | |
return static::class . 'Presenter'; | |
} | |
} |
This file contains 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 namespace Acme\Core; | |
use McCool\LaravelAutoPresenter\BasePresenter; | |
class Presenter extends BasePresenter {} |
This file contains 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 namespace Acme\Reports; | |
use Acme\Core\PresentableModel; | |
class Report extends PresentableModel { | |
} |
This file contains 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 namespace Acme\Reports; | |
use Acme\Core\Presenter; | |
class ReportPresenter extends Presenter { | |
/** | |
* Create new ReportPresenter instance. | |
* @param Report $reports | |
*/ | |
public function __construct( Report $reports ) | |
{ | |
$this->resource = $reports; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment