Define default values for Laravel form fields

前端 未结 7 2147
感动是毒
感动是毒 2021-02-20 12:45

To pre-populate form field, we can add \'value\' to form field in create.blade.php:

{{ Form::text(\'title\', \'Some default title\') }}

Is ther

7条回答
  •  难免孤独
    2021-02-20 13:06

    Yes, let's consider the following example:

    View:

    {{ Form::text('title', $title) }}
    

    Controller:

    $title = 'Some default title';
    if($article) {
        $title = $article->title;
    }
    return View::make('user.login')->with('title', $title)
    

    Then you will have a text-input with either Some default title or the title from $article, if $article isn't equal to false

提交回复
热议问题