Download the PHP package crocodic/laravel-model without Composer
On this page you can find all versions of the php package crocodic/laravel-model. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download crocodic/laravel-model
More information about crocodic/laravel-model
Files in crocodic/laravel-model
Package laravel-model
Short Description Boost your laravel database relation with model enhancement
License MIT
Informations about the package laravel-model
Crocodic Laravel Model
An alternative laravel eloquent. Crocodic Laravel Model using Model, Repository and Service pattern. Model is a class that define anything about table columns. Repository is a class that define your own query method. And Service is a class that should define your own business logic query method.
Requirement
Laravel / Lumen 5. | 6. | 7. | 8.
Install Command
composer require crocodic/laravel-model
LUMEN USER:
after install with the composer then add this bellow to /bootstrap/app.php
at section Register Service Providers
$app->register(\Crocodic\LaravelModel\LaravelModelServiceProvider::class);
1. Create a model
Create a model from a table
php artisan create:model foo_bar_table
Create model for all tables
php artisan create:model
Create a model with other connection
php artisan create:model foo_bar_table --connection=con2
I assume that you have a table with the structure like bellow:
It will create a new model class file at with the following file structure :
Also create a new Repository class file, and a new Service class file.
/app/Repositories/Books.php
/app/Services/BooksService.php
You can set custom connection, table and primary key name
2. Using Crocodic Laravel Model class on your Controller
Crocodic Laravel Model use Model, Repository and Service pattern. If you want make a query, please use the Repository one instead of Model Class. Like example bellow: Insert at top of your controller class name.
3. Using Crocodic Laravel Model class that has a relation
I assume you have a table for book relation like bellow :
and your book structure to be like bellow:
Now you have to create a model for table, you can following previous steps.
I assume that you have create a model, so make sure that now we have two files in the
Open the Books model , and add this bellow method
Then open the FooController
As you can see now we can get the category name by using without any SQL Query or even Database Builder syntax. Also you can recursively go down to your relation with NO LIMIT.
4. How to Casting DB Builder Collection output to Crocodic Laravel Model Class?
You can easily cast your simple database builder collection to cb model class.
5. How to insert the data with Crocodic Laravel Model
You can easily insert the data with method like bellow:
Then if you want to get the last insert id you can do like bellow:
5. How to update the data with Crocodic Laravel Model
You can easily update the data, just find it for first :
5. How to delete the data?
You can easily delete the data, just find it for first :
or
Model Method Available
A One-To-Many Relationship
A One-To-One Relationship
Other Useful
All versions of laravel-model with dependencies
doctrine/dbal Version ^2.10
illuminate/support Version ^5.7|^6.0|^7.0|^8.0
illuminate/console Version ^5.7|^6.0|^7.0|^8.0
illuminate/database Version ^5.7|^6.0|^7.0|^8.0