Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MatusVrsansky's avatar

How to get value from textarea?

I would like to get data from my textarea, and later save them to the variable in my web.php, but , the compiler says, that class Textarea is not defined...

Someone know, how to solve this problem?

Code in my view:

Description

{{ $profile->description}}

Code in my web.php

Route::post('insert_user_info', array(

'as' => 'insert_user_info',

function() {



  $info = Textarea::get('description');  
0 likes
5 replies
Snapey's avatar

Please format code blocks with ``` on a line before and after code

MatusVrsansky's avatar

view code:

<form class="form-horizontal" method="POST" action="{{route('insert_user_info')}}">                         
        <table class="table">
            <tr>
                <th><h4>Popis</h4></th>
                <td><textarea class="form-control" name="description" rows="7">{{ $profile->consultation_hours }}</textarea></td>
            </tr>
    </table>

web.php code

Route::post('insert_user_info', array(

    'as' => 'insert_user_info',

    function() {

   
      $info= Textarea::get('description');  


 }


));

sorry , my mistake. I am newbie on the laracasts

Snapey's avatar

What is the class Textarea?

Try dumping the value to check what you get at the server

Route::post('insert_user_info', function(){

    dd(request()->description);

})->name('insert_user_info');

LaraBABA's avatar

In Laravel 5.5 what I usually do is this:

First create a controller that will be used to manipulate your data with the console, type:

php artisan make:controller NameHereController

In my form, I put an action with this controller name as

<form id="uploadForm" method="POST" action="{{ action('NameHereController@store') }}"
                              enctype="multipart/form-data">
                            {{ csrf_field() }}


<div class="form-group{{ $errors->has('description') ? ' has-error' : '' }} formField">
<label for="comment">Describe what you see(To help the DirtBusters finding it)</label>
 <textarea class="form-control" rows="5" name="description" maxlength="750" required
                                          autofocus>{{ ucfirst($markers->description) }}</textarea>

                                @if ($errors->has('description'))
                                    <span class="help-block">
                    <strong>{{ $errors->first('description') }}</strong>
                    </span>
                                @endif
                            </div>

                            <div class="form-group">
                                <button type="submit" name="button" class="btn btn-primary">Send!</button>
                            </div>

</form>




Remember to add the {{ csrf_field() }} or you will get problems.

Now in the controller Store function, I add this:

public function store(Request $request)<--this is the data from your form
    {

        $validator = Validator::make($request->all(), [
            'description' => 'required|string|min:2|max:750'<--set it to whatever you like
        ]);

        if ($validator->fails()) {  <--if the validation fails return with the errors

            return back()
                ->withErrors($validator)
                ->withInput();
}else{

            DB::table('yourTable')->insert(array(
                'description' => $request->get('description')
            ));

            return back()->with('success', 'Thank you for your hard work!');

Hope this helps,

ps:I used the multipart in my form post because initially, this form had images in the request....

MatusVrsansky's avatar

Definitely will try it, but please, what means variable: {{ ucfirst($markers->description) }} ?

Is it like my $profile->consultation_hours variable in my view???

Please or to participate in this conversation.