The create page of Laravel shares a form with the edit page, but the edit page has a variable. The create page does not have a variable. Can it be shared?

Source: Internet
Author: User
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.$postAndwebMiddleware (sessionYes. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.