|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Larrock\Core\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use Larrock\Core\Component; |
|
6
|
|
|
use Illuminate\Http\Request; |
|
7
|
|
|
use Larrock\Core\Helpers\MessageLarrock; |
|
8
|
|
|
use Larrock\Core\Helpers\FormBuilder\FormCategory; |
|
9
|
|
|
use Larrock\ComponentCategory\Models\Category; |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
trait AdminMethodsCreate |
|
12
|
|
|
{ |
|
13
|
|
|
/** @var Component */ |
|
14
|
|
|
protected $config; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Creating a new resource. |
|
18
|
|
|
* @param Request $request |
|
19
|
|
|
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse |
|
20
|
|
|
* @throws \Exception |
|
21
|
|
|
*/ |
|
22
|
|
|
public function create(Request $request) |
|
23
|
|
|
{ |
|
24
|
|
|
$post_rows = [ |
|
25
|
|
|
'title' => $request->get('title', 'Новый материал'), |
|
26
|
|
|
'url' => str_slug($request->get('title', 'Новый материал')), |
|
27
|
|
|
]; |
|
28
|
|
|
|
|
29
|
|
|
if ($request->has('category')) { |
|
30
|
|
|
$post_rows['category'] = $request->get('category'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
foreach ($this->config->rows as $row) { |
|
34
|
|
|
if (isset($row->modelChild) && $row->modelChild === \config('larrock.models.category', Category::class)) { |
|
35
|
|
|
if (! empty($request->get($row->name))) { |
|
36
|
|
|
if ($findCategory = \LarrockCategory::getModel()->whereComponent($this->config->name)->whereId($request->get($row->name))->first()) { |
|
|
|
|
|
|
37
|
|
|
$post_rows[$row->name] = $findCategory->id; |
|
38
|
|
|
} else { |
|
39
|
|
|
MessageLarrock::danger('Раздела с переданным id:'.$request->get($row->name).' не существует'); |
|
40
|
|
|
|
|
41
|
|
|
return back()->withInput(); |
|
42
|
|
|
} |
|
43
|
|
|
} else { |
|
44
|
|
|
if ($findCategory = \LarrockCategory::getModel()->whereComponent($this->config->name)->first()) { |
|
45
|
|
|
$post_rows[$row->name] = $findCategory->id; |
|
46
|
|
|
} else { |
|
47
|
|
|
MessageLarrock::danger('Создать материал пока нельзя. Сначала создайте для него раздел'); |
|
48
|
|
|
|
|
49
|
|
|
return back()->withInput(); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$store = Request::create('/admin/'.$this->config->name, 'POST', $post_rows); |
|
56
|
|
|
|
|
57
|
|
|
if (! method_exists($this, 'store')) { |
|
58
|
|
|
$trait = new class { |
|
59
|
|
|
use AdminMethodsStore; |
|
|
|
|
|
|
60
|
|
|
}; |
|
61
|
|
|
|
|
62
|
|
|
return $trait->updateConfig($this->config)->store($store); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return $this->store($store); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths