Laravel error: Call to a member function format() on string

前端 未结 3 1787
心在旅途
心在旅途 2020-12-10 00:52

I am using Laravel 5.3.

There is a field expired_at in table articles

public function store(Request $re         


        
相关标签:
3条回答
  • 2020-12-10 01:39

    I think this is the way. It will not throw error

    {{ Carbon\Carbon::parse($article->expired_at)->format('Y-m-d') }}
    
    0 讨论(0)
  • 2020-12-10 01:55

    In your Article class add following property:

    /**
     * The attributes that should be mutated to dates.
     *
     * @var array
     */
    protected $dates = ['expired_at'];
    

    Docs

    0 讨论(0)
  • 2020-12-10 01:55

    If you use DB:: to retrieve complex data, you can´t use mutators. In this situation I use this:

    {{ date('m-Y', strtotime($hora->Fecha)) }}
    

    Or

    {{ date('m-Y', strtotime($hora ?? ''->Fecha)) }}
    

    Where "Fecha" is a datetime value.

    0 讨论(0)
提交回复
热议问题