Carbon.php No separation symbol found. No data available.

First I retrieve all the records,

//get inventory items
$inv = inventory::all();

and then I loop through the extracted records and modify the created_at and updated_at data to make it more human-readable by date.

foreach($inv as $i){
    $i->created_at = date("M d, Y",strtotime($i->created_at));
    $i->updated_at = date("M d, Y",strtotime($i->updated_at));
}

but he returns me this error,

InvalidArgumentException in line Carbon.php 425: Unexpected data found. Unexpected data received. Separation character not found Missing data

any ideas, help, tips, suggestions, recommendations, please

here is my model

namespace App;

use Illuminate\Database\Eloquent\Model;

class inventory extends Model
{
    protected $table = "inventory";
    protected $primaryKey = "item_id";
    public $incrementing = false;

    public function profile(){
        return $this->belongsTo('App\profile','username');
    }
    public function inventory_images(){
        return $this->hasMany('App\inventory_images','item_id');
    }
}

and in the blade i can just use

{{ date("M d, Y",strtotime($i->created_at)) }}

{{ date("M d, Y",strtotime($i->updated_at)) }}

and it works fine.

+10
source share
1 answer

, . , , interacts.

, accessor, created_at. updated_at.

public function getCreatedAtAttribute($timestamp) {
    return Carbon\Carbon::parse($timestamp)->format('M d, Y');
}

, $model->created_at, .

- , , , , timestamp , :

protected $dateFormat = 'M d, Y';

Sidenote
, Carbon, , , $table->timestamps(), created_at updated_at.
, protected $dates = [], Carbon.

+6

All Articles