Editor can't find class from static method call
The Carbon class exists in vendor/nesbot/carbon/src/Carbon/Carbon.php, and PHPStorm is able to find it from another call in another file, but I'm not seeing why it can't find it in my new model file (under the app folder) even if I delete the preceding `Carbon\` text.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Abc extends Model
{
// A B C table in the Data schema
const CREATED_AT = 'date_time';
const UPDATED_AT = '';
public function getCreatedAtAttribute($date)
{
return Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $date)->format('Y-m-d');
}
public function getUpdatedAtAttribute($date)
{
return Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $date)->format('Y-m-d');
}
public function stuff()
{
return $this->hasMany('App\Stuff', 'ID_papa');
}
}
请先登录再写评论。
Hi there,
Based on your code sample, IDE is correct -- it tries to locate \App\Carbon\Carbon since you do not have leading slash in your Carbon\Carbon call.
Import your carbon class and then use just Carbon -- the best way.