我试图通过使用Laravel构建的web服务中的表单插入数据(日期类型数据)。
律师事务所。刀身php代码:
@extends('layout.app', ["current" => "solicitacaos"])
@section('body')
<div class="container">
<div class="card-border">
<div class="card-body">
<h3 class="card-title">Solicitações</h3>
<table class="table table-striped table-bordered table-hover">
<tr>
<th> Professor
</th>
<th>
Criação
</th>
<th>
Data Solicitação
</th>
<th>
Nome do Produto
</th>
<th>
Observações
</th>
<th>
Status
</th>
<th>
Ação
</th>
</tr>
@foreach($sols as $sol)
@php
dd($sol)
@endphp
<tr>
<td> {{$sol->nome_professor}}
</td>
<td> {{$sol->criacao}}
</td>
<td> {{dd($sol)}}
</td>
<td> {{$sol->nome_produto}}
</td>
<td> {{$sol->observacao}}
</td>
<td> {{$sol->status}}
</td>
<td>
<a href="/solicitacao/apagar/{{$sol->id}}" class="btn btn-sn btn-danger">Cancelar</a>
</td>
</tr>
@endforeach
</table>
</div>
</div>
</div>
@endsection
错误出现在“{\Carbon\Carbon::parse($sol->requestacao_data->from_date)->gt;format('d/m/Y')}”行上。”
即使我将行“{\Carbon\Carbon::parse($sol->requestacao_data->from_date)->gt;format('d/m/Y')}}”更改为“{{$sol->requestacao_data}”,我仍然会收到相同的错误。
控制器代码为:
$date_sol = new DateTime();
$date_sol = DateTime::createFromFormat("d/m/Y",$request->input('solicitacao_data'));
$sol->solicitacao_data = $date_sol;
$sol->save();
我正在插入'25/2/2020',但我得到以下错误:
Facade\Ignition\Exceptions\ViewException未定义属性:
stdClass::$requestacao_数据(视图:
C:\xampp\htdocs\laravel\workflow novo\resources\views\requestacoes。刀身(php)
数据库表是通过迁移创建的,如下所示:
<?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');
}
}
我需要使用Laravel存储和恢复日期。我怎样才能不犯上面的错误呢?
**我注意到,如果我试图节省时间,则数据库保存无法正常工作。例如,以下代码:
$date_sol = Carbon::createFromFormat("d/m/Y H:i:s","20/12/2020 01:00:00");
$sol->solicitacao_data = $date_sol;
将以下数据存储在Acao_数据列中。
MariaDB [login]> select * from solicitacaos;
+----+----------+------------+------------+------------+------------------+-----
----------------+---------------------+
| id | id_users | id_produto | status | observacao | solicitacao_data | crea
ted_at | updated_at |
+----+----------+------------+------------+------------+------------------+-----
----------------+---------------------+
| 24 | 1 | 1 | Em Análise | blabla | 2020-12-20 | 2019
-12-30 23:47:52 | 2019-12-30 23:47:52 |
| 25 | 1 | 1 | Em Análise | blabla | 2020-12-20 | 2019
-12-31 01:22:50 | 2019-12-31 01:22:50 |
| 26 | 1 | 1 | Em Análise | blabla | 2020-12-20 | 2019
-12-31 01:23:08 | 2019-12-31 01:23:08 |
| 27 | 1 | 1 | Em Análise | blabla | 2020-12-20 | 2019
-12-31 01:27:33 | 2019-12-31 01:27:33 |
+----+----------+------------+------------+------------+------------------+-----
----------------+---------------------+
4 rows in set (0.001 sec)
请注意,只存储了日期。
我已经执行了请求中的dd($sol)命令。刀身php我有以下几点:
{#341 â¼
+"id": 1
+"status": "Em Análise"
+"nome_professor": "Olavo"
+"criacao": "2019-12-31 02:08:11"
+"nome_produto": "Cadeira"
+"observacao": "awdcasd"
}
尽管表中有我之前显示的列。
MariaDB[登录]>从Acaos中选择*;
+----+----------+------------+------------+------------+------------------+-----
----------------+---------------------+
|id | id |用户| id |产品|状态|观察|请求|数据| crea
ted|u在|更新|u在|
+----+----------+------------+------------+------------+------------------+-----
----------------+---------------------+
|24 | 1 | 1 | Em AnÃlise | blabla | 2020-12-20 | 2019
-12-30 23:47:52 | 2019-12-30 23:47:52 |
|25 | 1 | 1 | Em Anlise | blabla | 2020-12-20 | 2019
-12-31 01:22:50 | 2019-12-31 01:22:50 |
|26 | 1 | 1 | Em AnÃlise | blabla | 2020-12-20 | 2019
-12-31 01:23:08 | 2019-12-31 01:23:08 |
|27 | 1 | 1 | Em Anlise | blabla | 2020-12-20 | 2019
-12-31 01:27:33 | 2019-12-31 01:27:33 |
+----+----------+------------+------------+------------+------------------+-----
----------------+---------------------+
一组4行(0.001秒)