ken4ward
ken4ward

Reputation: 2296

Laravel not saving textarea value in the db

I can't really figure out what is wrong why this code is not saving textarea value. All other things are working fine, except the saving of textarea content. If I remove the textarea code it saves successfully.

This is the the controller action:

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();
        }
    }

This is the blade view:

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

This is the request file;

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'
            ];
    }

Upvotes: 0

Views: 3499

Answers (1)

Qazi
Qazi

Reputation: 5135

change your these lines

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

to this

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

and then make a try, remember, as you set textarea min:200 characters, then you should enter 200 or above characters.

Upvotes: 1

Related Questions