Download the PHP package zlt/laravel-api-auth without Composer
On this page you can find all versions of the php package zlt/laravel-api-auth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-api-auth
Laravel Api Auth
This package provides basic api authorization and easy-to-use servicing your Models.
- Using this package, you don't need to write your own authorization logic for your api. Even if you don't want to, you can use actions classes to ease your own authorization.
- You don't have to write your own query.
Instead of using
Post::whereBetween(...)->orderByDesc(...)->get()
, you can use like
Table Of Contents
- Installation
- Publish config file
- Authorization
- Manually Login and Register
- Servicing
- Why you would need this?
- How to use?
- Caching Response
- License
- Conclusion
Installation
Publish config file
The following are the default config.
Authorization
There are already api routes defined for you to authorize a user such as /api/login
, /api/register
and /api/delete
.
In order to disable those routes, you can set the shouldIncludeRoutes
option to false
in
the config/laravel-api-auth.php
file.
Manually Login and Register
-
Login a user
Zlt\LaravelApiAuth\Actions\Login:class
can be used to log user in.- Create instance.
- invoke the instance
values
as parameter. Let action handle validation and checking credentials. Zlt\LaravelApiAuth\Support\ApiResponse
will be always returned with corresponding message, additional data and status code.
-
Registering a user
Zlt\LaravelApiAuth\Actions\Register::class
can be used to register a user.- Create instance.
- invoke the instance
values
as parameter. Let action handle validation and checking credentials. Zlt\LaravelApiAuth\Support\ApiResponse
will be always returned with corresponding message, additional data and status code.
-
Deleting a user
Zlt\LaravelApiAuth\Actions\Delete::class
can be used to delete a user.- Create instance.
- invoke the instance
values
as parameter. Let action handle validation and checking credentials. Zlt\LaravelApiAuth\Support\ApiResponse
will be always returned with corresponding message, additional data and status code.
Servicing
Why you would need this?
The idea of servicing is to provide a easy-to-use way to build database query and execute it.
For example, you have a Post
model and you want to build query instead of using
like Post::whereBetween('date',['2022-01-01','2022-06-01'])->orderByDesc('date')->get()
. Then you can use the
following service:
Then call static method get
or count
to get the result.
How to use it?
-
First, you need to extend
Zlt\LaravelApiAuth\Services\BaseService
and implement thegetInstance
method. -
Then, you need to pass your
Builder
instance to constructor or inside the constructor. -
You can use some built-in features offered by package.
orderBy
limit
offset
hiddenFields
selectedFields
For example,
-
You can register queryable column and cast the value before using in query. For example, you want to get posts between two dates. ( Assume there is
date
column)You can also cast the value before using in query.
Caching response
This package also offers a trait to cache response.
License
MIT
Conclusion
Why I created this package is because I needed to use such features in my projects. But now I think it would probably help others too. So I decided to share it with you. I hope you find it useful.
Feel free to contribute to this package.
If you find it useful, please give it a star or buy me a coffee via Binance.
Cheers!
All versions of laravel-api-auth with dependencies
illuminate/validation Version ^9.0
illuminate/database Version ^9.0
jenssegers/mongodb Version ^3.9
illuminate/http Version ^9.0