forked from basic-app/crud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateCrudActionTrait.php
47 lines (37 loc) · 1.11 KB
/
CreateCrudActionTrait.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
* @author Basic App Dev Team
* @license MIT
* @link http://basic-app.com
*/
namespace BasicApp\Crud;
use Config\Services;
trait CreateCrudActionTrait
{
protected function createCrudAction(string $class, array $params = [])
{
$params['modelClass'] = $this->modelClass;
$params['renderFunction'] = function(string $view, array $params = []) {
if (method_exists($this, 'render'))
{
return $this->render($view, $params);
}
else
{
return view($view, $params);
}
};
$params['redirectBackFunction'] = function($returnUrl) {
if (method_exists($this, 'redirectBack'))
{
return $this->redirectBack($returnUrl);
}
else
{
return Services::response()->redirect($returnUrl);
}
};
$params['returnUrl'] = property_exists($this, 'returnUrl') ? $this->returnUrl : null;
return $class::factory($params);
}
}