Laravel's create page shares a form with the edit page, but the edit view page has a variable, that is, the content queried from the Controller is returned to the view, while the create controller, no data is returned. In this way, an error will be reported in create when the shared form is shared, indicating that there are undefined... laravel's create page and edit page share the form,
However, the edit view page has a variable, that is, to query the content from the Controller, and then return to the view,
The create controller does not return data,
In this way, the shared form will report an error in create, saying that there are undefined variables,
How can this problem be solved?
Reply content:
Laravel's create page and edit page share the form,
However, the edit view page has a variable, that is, to query the content from the Controller, and then return to the view,
The create controller does not return data,
In this way, the shared form will report an error in create, saying that there are undefined variables,
How can this problem be solved?
Just one copy.
Suppose you return a model variable to the blade template engine.$post
Andweb
Middleware (session
Yes. You can share oneform.blade.php
,:
1. retain the old input items (using the old method), such as submitting a form, but the verification fails. After the page is submitted and refreshed, the data submitted last time is retained.
2. Old input items do not need to be retained
Write two copies or check whether the variable exists as needed
You do not need to write two copies,
Create a form. blade. php file, store the form options, and use isset to determine whether the output exists or not, or you can use Forms & HTML builder to make it easier.
If you write an input form yourself, write it as follows:
If laravel's Form is used, it is more concise:
InCreate. blade. phpMedium:
{!! Form: open (['url' => 'Article'])!} @ Include ('Article. _ Form', ['submitclick' => 'add an article ']) {! Form: close ()!!}
InEdit. blade. phpMedium
{!! Form: model ($ article, ['method' => 'patch ', 'url' => ['Article', $ article-> id])!} @ Include ('Article. _ Form', ['submitclick' => 'modify files']) {! Form: close ()!!}
A public form section is required:_ Form. blade. phpIs the form part.
I don't think we should use a framework to use it. laravel provides us with a lot of convenient operations. If we are using this framework, we should try to accept them.