| Total Complexity | 4 |
| Total Lines | 73 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | class CreateArticle extends Component |
||
| 17 | { |
||
| 18 | use AuthorizesRequests; |
||
| 19 | use Toastable; |
||
| 20 | use WithFileUploads; |
||
|
|
|||
| 21 | |||
| 22 | /** |
||
| 23 | * The form used to create/update a model. |
||
| 24 | * |
||
| 25 | * @var BlogArticleForm |
||
| 26 | */ |
||
| 27 | public BlogArticleForm $form; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Used to show the create modal. |
||
| 31 | * |
||
| 32 | * @var bool |
||
| 33 | */ |
||
| 34 | public bool $showModal = false; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Create a blank model and assign it to the model. (Used in create modal) |
||
| 38 | * |
||
| 39 | * @return void |
||
| 40 | */ |
||
| 41 | #[On('create-article')] |
||
| 42 | public function createArticle(): void |
||
| 43 | { |
||
| 44 | $this->authorize('create', BlogArticle::class); |
||
| 45 | |||
| 46 | $this->form->reset(); |
||
| 47 | $this->form->searchCategories(); |
||
| 48 | |||
| 49 | $this->showModal = true; |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Validate and save the model. |
||
| 54 | * |
||
| 55 | * @return void |
||
| 56 | * |
||
| 57 | * @throws Throwable |
||
| 58 | */ |
||
| 59 | public function create(): void |
||
| 60 | { |
||
| 61 | $this->authorize('create', BlogArticle::class); |
||
| 62 | |||
| 63 | $this->validate(); |
||
| 64 | |||
| 65 | $this->form->create(); |
||
| 66 | |||
| 67 | $this->showModal = false; |
||
| 68 | |||
| 69 | redirect() |
||
| 70 | ->route('admin.blog.article.index') |
||
| 71 | ->success('Your article has been created successfully !'); |
||
| 72 | } |
||
| 73 | |||
| 74 | public function render() |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * We must use a function in the component. |
||
| 81 | * |
||
| 82 | * @param string $value |
||
| 83 | * |
||
| 84 | * @return void |
||
| 85 | */ |
||
| 86 | public function searchCategories(string $value = ''): void |
||
| 89 | } |
||
| 90 | } |
||
| 91 |