jamesmills / laravel-timezone

Enable user Timezones in your application.
MIT License
677 stars 91 forks source link

use in model #48

Closed MohammaddReza closed 3 years ago

MohammaddReza commented 4 years ago

i want to use this command in my model like this:

    public function getTimeAttribute($value){
        return Timezone::convertFromLocal($this->start);
    }

but it returns this error: Class 'App\Timezone' not found

SamuelNitsche commented 4 years ago

You should import the Timezone class.

MohammaddReza commented 4 years ago

im using this class but still have an error. use App\Timezone;

SamuelNitsche commented 4 years ago

You have to use JamesMills\LaravelTimezone\Timezone

MohammaddReza commented 4 years ago

now i have this error: Non-static method JamesMills\LaravelTimezone\Timezone::convertToLocal() should not be called statically im using vue (not blade) and i have to use this with api this is my function:

    public  function getTimeAttribute(){
        return Timezone::convertToLocal($this->created_at);
    }
SamuelNitsche commented 4 years ago

Sorry, my bad. The package offers a Facade. You should use this one. So please replace use JamesMills\LaravelTimezone\Facades\Timezone

MohammaddReza commented 4 years ago

thank you this is work very well.

SamuelNitsche commented 4 years ago

So the issue is fixed?

jamesmills commented 3 years ago

Sorry I'm late to review this @MohammaddReza.

Thank you very much @SamuelNitsche for taking the time to provide help and a solution.

Stay safe!