Laravel没有在db中保存textarea值

时间:2016-03-20 14:39:05

标签: php html5 save laravel-5.1 laravel-blade

我无法弄清楚为什么这段代码没有保存textarea值的错误。除了节省textarea内容外,其他所有方面都运行良好。如果我删除了textarea代码,它会成功保存。

这是控制器动作:

public function store(CompanyRequest $companyRequest)
    {
       $company = new Company;

       if($companyRequest->isMethod('post')){

       $company->companyname    = $companyRequest->companyname;
       $company->companydescription    = $companyRequest->companydescription;

       $company->save();
       return redirect()->route('companyindex')->with('message', 'Your question has been posted.');
       }else{
            return redirect('company-create')->withErrors($companyRequest)->withInput();
        }
    }

这是刀片视图:

{!! Form::textarea('companydescription', Input::old('companydescription'), ['class'=>'mid first-input-div', 'id'=>'companydescription']) !!}

这是请求文件;

class CompanyRequest extends Request
{
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
                'companyname'           => 'required|min:5|max:300',
                'companydescription'    => 'required|min:200|max:250'
            ];
    }

1 个答案:

答案 0 :(得分:1)

更改这些行

$company->companyname    = $companyRequest->companyname;
$company->companydescription    = $companyRequest->companydescription;

到这个

$company->companyname    = $companyRequest->input('companyname');
$company->companydescription    = $companyRequest->input('companydescription');

然后尝试一下,记住,当你设置textarea min:200字符时,你应该输入200或以上的字符。