0

Hi i tried everything i found on Google but nothing work, i have always the error trailing data when i'm trying to insert date in my db. i Hope someone can help me. Thanks a lot and sorry for my english.

//here's my model location

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Location extends Model
{
    protected $table = 'location';

}

//Heres's My migration

<?php

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

class Location extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('location', function(Blueprint $table) {
            $table->bigIncrements('id');
            $table->date('start');
            $table->date('end');
        });
    }

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

//And here's my method to store date in my controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Location;
use Carbon\Carbon ;
    public function storeDate(Request $request){

        $location = new Location();

        $start  = Carbon::createFromFormat('m/d/y', $request->input("start"));
        $end  = Carbon::createFromFormat('m/d/y', $request->input("end"));

        $location->start = $start;
        $location->end = $end;

        $location->save();

        return redirect('/myCar');

    }
}

My form

 <form class="form-inline" method="POST" action="/storedate">
              @csrf
              <div class="modal-body">           
                <label class="sr-only" for="inlineFormInputName2"></label>
                <input type="text" class="form-control mb-2 mr-sm-2" id="inlineFormInputName2" placeholder="dd/mm/yyyy" value="20/04/2019" name="start">         
                <label class="sr-only" for="inlineFormInputGroupUsername2"></label>
                <div class="input-group mb-2 mr-sm-2">
                  <input type="text" class="form-control" id="inlineFormInputGroupUsername2" placeholder="dd/mm/yyyy" value="20/04/2019" name="end">
                </div>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="submit" class="btn btn-primary">Send message</button>
              </div>
            </form>
Dirk
  • 55
  • 6
  • `m/d/y` is there a month 20? you probably should be validating the data before trying to use it – lagbox Dec 16 '19 at 11:51
  • you can try this https://stackoverflow.com/questions/50208932/laravel-model-trailing-data-when-save-the-model and also define your $fillable columns in the model page – Rayleen Dec 16 '19 at 12:11
  • you should answer you own question and accept it so that people aren't looking to help you answer something you already solved. – Azeame Dec 17 '19 at 02:33

1 Answers1

0

It's ok i found it. In m/d/y my y need to be in uppercase :

m/d/Y

Thank you for your support !

Obsidian
  • 3,719
  • 8
  • 17
  • 30
Dirk
  • 55
  • 6