Livewire: Same Component for Create and Edit Forms

Livewire: Same Component for Create and Edit Forms

Laravel Daily

1 год назад

13,623 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Gijs
Gijs - 27.08.2023 14:39

Is there a way to do this with livewire V3 and the new FormObjects?

Ответить
José Osório
José Osório - 07.08.2023 17:27

What if you need to stay on the same page after creating a Product? How do you reset it? I'm sorry, but for me, this lesson is not 100% accurate. If you inject the model into the mount method, you cannot reset it later. In this case, the problem goes unnoticed, as the user is being redirected to another page after creating the Product.

Ответить
Anwar Barakat
Anwar Barakat - 27.04.2023 12:56

Hello sir.
This was perfect as for my current project.
but after add or edit a new product I want to empty the form , i use
$this->unset('product');
but shows me this error
$product must not be accesses before initilized.
although I passed it in mount method
public function mount(Product $product){
$this->product = $product;
}

Ответить
Ilham Pamungkas
Ilham Pamungkas - 30.03.2023 20:31

Its spa ? No refresh sir ?

Ответить
Riccardo Tassinari
Riccardo Tassinari - 29.03.2023 23:53

The mount parameter can be used for 3 different purposes:
- passing a numerical id: the mount load the model with the given Id (edit mode)
- passing an array: the mount initializes a new model with the given data (create mode with fields preset)
- passing null: a new empty model is initialized

Ответить
Salah eddine Bendyab
Salah eddine Bendyab - 29.03.2023 12:38

There is a problem if i have a unique item in validation ?

Ответить
Khizer
Khizer - 29.03.2023 10:41

Useful

Ответить
dody ginandjar
dody ginandjar - 29.03.2023 09:54

Hai Povilas, i am a fan of livewire . I always create crud using full page component with modal for create and edit. But I have problem with datepicker in modal. I hope you make tutorial about solving it. So far , I create non-modal form if the crud need datepicker.

Ответить
Marvellous Ifezue
Marvellous Ifezue - 29.03.2023 09:05

Hey Povilas, I'm a pure livewire fan, but I'd love to ask if it would be able to manage around 10k concurrent users

I've been assigned to create a new project

Ответить
RS
RS - 29.03.2023 08:57

Sry for the change of subject, but can anyone help me to explain, why the following code is working perfect on my local machine (Windows, Xampp 3.3.0) and doesn't work on my server (PHP 8.1, MySQL 8.0).

return Order::wherehas('testcases', function (Builder $query){
$query
->where('next_exam', '<>', '')
->where('next_exam', '>=', Carbon::now()->addMonths(1)->firstOfMonth()->format('Y-m-d'))
->where('next_exam', '<=', Carbon::now()->addMonths(1)->endOfMonth()->format('Y-m-d'));
})->with(['testcases' => function (Builder $query){
$query
->where('next_exam', '<>', '')
->where('next_exam', '>=', Carbon::now()->addMonths(1)->firstOfMonth()->format('Y-m-d'))
->where('next_exam', '<=', Carbon::now()->addMonths(1)->endOfMonth()->format('Y-m-d'));
}])->with('company:id,name')->get()

Order hasMany testcases
Order hasOne company

I want to get only those orders, which has a testcase->next exam on the next month, and afterward load those testcases

Ответить
Noble Hara
Noble Hara - 29.03.2023 08:07

First one here. This is perfect as for my next project I want to forego Javascript and try Livewire fullout

Ответить