File tree 2 files changed +16
-6
lines changed
2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change 3
3
namespace Coderflex \LaravelPresenter \Exceptions ;
4
4
5
5
use Exception ;
6
+ use Illuminate \Database \Eloquent \Model ;
6
7
7
8
class PresenterException extends Exception
8
9
{
@@ -19,4 +20,18 @@ class PresenterException extends Exception
19
20
* @var int
20
21
*/
21
22
protected $ code = 500 ;
23
+
24
+ /**
25
+ * Method for Presenter Implementation absence on the model
26
+ * @param Model $model
27
+ * @return self
28
+ */
29
+ public static function interfaceNotImplemented (Model $ model ): self
30
+ {
31
+ return new self ((__ (':model should implements :interface interface ' , [
32
+ 'model ' => get_class ($ model ),
33
+ 'interface ' => '\Coderflex\LaravelPresenter\Concerns\CanPresent ' ,
34
+ ])
35
+ ));
36
+ }
22
37
}
Original file line number Diff line number Diff line change @@ -17,12 +17,7 @@ abstract class Presenter
17
17
public function __construct (Model $ model )
18
18
{
19
19
if (! $ model instanceof \Coderflex \LaravelPresenter \Concerns \CanPresent) {
20
- throw new PresenterException (
21
- __ (':model should implements :interface interface ' , [
22
- 'model ' => get_class ($ model ),
23
- 'interface ' => '\Coderflex\LaravelPresenter\Concerns\CanPresent ' ,
24
- ])
25
- );
20
+ throw PresenterException::interfaceNotImplemented ($ model );
26
21
}
27
22
28
23
$ this ->model = $ model ;
You can’t perform that action at this time.
0 commit comments