1

insert and edit the registry but no date columns. |

programming seemingly fine, but failed to get the date field is properly registered.

use UTF8 encoding, locale is (Es)

why? T_T

Table

Schema::create('products', function(Blueprint $table)
    {
        $table->increments('id');
        $table->integer('subclassproduct_id')->unsigned();
        $table->integer('branch_id')->unsigned();
        $table->integer('coin_id')->unsigned();
        $table->string('code', 50);
        $table->string('name', 100);
        $table->string('description', 200);
        $table->text('observation');
        $table->decimal('price', 5,2);
        $table->date('validity_since');
        $table->date('validity_until');
        $table->enum('state', ['Activo', 'Desactivado']); 
        $table->softDeletes();
        $table->timestamps();

        $table->foreign('subclassproduct_id')
            ->references('id')->on('subclasses_products')
            ->onUpdate('CASCADE')
            ->onDelete('CASCADE');  

        $table->foreign('branch_id')
            ->references('id')->on('branches')
            ->onUpdate('CASCADE')
            ->onDelete('CASCADE');

        $table->foreign('coin_id')
            ->references('id')->on('coins')
            ->onUpdate('CASCADE')
            ->onDelete('CASCADE');
    });

Model

this is the model of the table

class Product extends Model {
use  SoftDeletes; // for soft delete

protected $table = 'products';

protected $fillable = [
    'subclassproduct_id', 'branch_id', 'coin_id', 'code' ,'name', 'description', 'observation', 'price', 'validity_since', 'validity_until', 'state'
];

protected $dates = ['deleted_at'];   }

Controller

this is the Controller of the table

    public function update(EditProductRequest $request, $id)
{
    $Product = Product::findOrFail($id);
    $Product->fill($request->all());

    $request->merge(array('validity_since' => Carbon::createFromFormat('d/m/Y', $request->get('validity_since') )->toDateString()));
    $request->merge(array('validity_until' => Carbon::createFromFormat('d/m/Y', $request->get('validity_until') )->toDateString()));



    $Product->save();

    return redirect()->route('administrar.products.index');
}

1 Answer 1

1

Move these lines before fill:

$request->merge(...);
$request->merge(...);

Then use fill and rest of the code:

$Product->fill($request->all());
$Product->save();

// refirect or whatever...

BTW, you may use single merge with an array:

$request->merge([
    'validity_since' => 'value',
    'validity_until' => 'value'
]);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you I was so overwhelmed I did not see

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.