Sunday 29 December 2019

Undefined property: > stdClass error when using date type column on Laravel. How can I solve it?

I am trying to insert data (date type data) through a form in a web service built with Laravel.

the solicitacoes.blade.php code:

@foreach($sols as $sol)
                    <tr>
                        <td> 
                        </td>
                        <td> 
                        </td>
                        <td> 
                        </td>
                        <td> 
                        </td>
                        <td> 
                        </td>
                        <td> 
                        </td>
                        <td>
                            <a href="/solicitacao/apagar/" class="btn btn-sn btn-danger">Cancelar</a>
                        </td>
                    </tr>
                    @endforeach

The controler code is:

$date_sol = new DateTime();
$date_sol = DateTime::createFromFormat("d/m/Y",$request->input('solicitacao_data'));

$sol->solicitacao_data = $date_sol;

$sol->save();

I am inserting '25/2/2020', but I get the following error:

Facade\Ignition\Exceptions\ViewException Undefined property: stdClass::$solicitacao_data (View: C:\xampp\htdocs\laravel\workflow-novo\resources\views\solicitacoes.blade.php)

The database table is created through migrations, as follows:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateSolicitacaosTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('solicitacaos', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger('id_users')->unsigned();
            $table->foreign('id_users')->references('id')->on('users');
            $table->bigInteger('id_produto')->unsigned();
            $table->foreign('id_produto')->references('id')->on('produtos');
            $table->string('status');
            $table->string('observacao');
            $table->date('solicitacao_data');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('solicitacaos');
    }
}

I need to store and recover the date using Laravel. How can I make it without the error above?



from Undefined property: > stdClass error when using date type column on Laravel. How can I solve it?

No comments:

Post a Comment