Usage
How to Use Intervention Zodiac
5k Downloads / Month
Open Source MIT License
5k Downloads / Month
Open Source MIT License
Use the calculator class to calculate zodiac
signs from various date types. The method zodiac()
acts
as a central starting point. Read the documentation on the calculator
class for more information.
use Intervention\Zodiac\Calculator;
use Intervention\Zodiac\Zodiacs\Scorpio;
$calculator = new Calculator();
$sign = $calculator->zodiac('2000-10-27');
if ($sign instanceof Scorpio) {
// zodiac sign is scorpio ...
}
It's also possible to start the calculation with a static call. See the following example.
use Intervention\Zodiac\Calculator;
$sign = Calculator::zodiac('2000-10-27');
The package comes with an integrated bridge to the Laravel Framework and includes a service provider and facade. After the installation Laravel will automatically register the service provider.
In Laravel, the make()
method is used. However, the base class is
different since we are now working with the facade. The service providers
injects the framework's translator automatically. See the following example on
how to calculate a zodiac sign from a get parameter and you can start right
away.
use Illuminate\Support\Facades\Route;
use Illuminate\Http\Request;
use Intervention\Zodiac\Laravel\ZodiacFacade;
Route::get('/', function (Request $request) {
$sign = ZodiacFacade::make($request->input('birthday'));
return $sign->localized();
});
In Laravel the localized()
method returns by default in the currently
configured locale.
By including Intervention\Zodiac\Laravel\Traits\CanResolveZodiac
your
Eloquent Model gets a new zodiac attribute, which is created based on the
birthday attribute of the current model and returns a zodiac object.
class User extends Model
{
// include trait
use \Intervention\Zodiac\Laravel\Traits\CanResolveZodiac;
// optional: If you want overwrite attribute. By default `birthday`
protected string $birthdayAttribute = 'date_of_birth';
}
// retrieve zodiac attribute
$user = App\User::create(['birthday' => '1980-03-15']);
$zodiac = $user->zodiac; // Intervention\Zodiac\Zodiacs\Pisces
Edit