-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3f9f4d8
Showing
41 changed files
with
500,894 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 4 | ||
trim_trailing_whitespace = true | ||
|
||
[*.yml] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/vendor | ||
Database Diagram.mwb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Gerardo J. Báez | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
# Vehicles Data for Laravel 5.2 | ||
|
||
This package allows you to work with vehicles Makes, Models and Years in | ||
Laravel 5.2. | ||
|
||
##### Where the data come from? | ||
|
||
The original list was collected from www.fueleconomy.gov. (They offer XML and | ||
CSV files). The list is updated and validated against some industry standards. | ||
|
||
## Content | ||
|
||
- [Installation](#installation) | ||
- [Composer](#composer) | ||
- [Service Provider](#service-provider) | ||
- [Config File, Migrations and Seeders](#config-file-migration-and-seeders) | ||
- [Traits and Contracts](#traits-and-contracts) | ||
- [Usage](#usage) | ||
- [The CSV File](#the-csv-file) | ||
- [Models](#models) | ||
- [Controllers](#controllers) | ||
- [Routes](#routes) | ||
- [License](#license) | ||
|
||
|
||
## Installation | ||
|
||
### Composer | ||
|
||
Pull this package through Composer (file `composer.json`) | ||
|
||
```js | ||
{ | ||
"require": { | ||
"php": ">=5.5.9", | ||
"laravel/framework": "5.2.*", | ||
"gerardojbaez/vehicle": "0.*" | ||
} | ||
} | ||
``` | ||
|
||
Run this command inside your terminal. | ||
|
||
composer update | ||
|
||
### Service Provider | ||
Add the package to your application service providers in config/app.php file. | ||
```php | ||
<?php | ||
|
||
'providers' => [ | ||
|
||
[...] | ||
|
||
/** | ||
* Third Party Service Providers... | ||
*/ | ||
'Gerardojbaez\Vehicle\VehicleServiceProvider', | ||
] | ||
``` | ||
|
||
### Config File, Migration and Seeders | ||
|
||
Publish package config file, migrations and seeders with the command: | ||
|
||
php artisan vendor:publish | ||
|
||
Then run migrations. | ||
|
||
php artisan migrate | ||
|
||
Then the vehicle seeder. | ||
|
||
php artisan db:seed --class VehiclesTablesSeeder | ||
|
||
### Traits and Contracts | ||
When one of your models has make, model and/or model year you can add the required relations with our traits. See the following example: | ||
|
||
```php | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
// [...] | ||
use Gerardojbaez\Vehicle\Contracts\HasMake as HasMakeContract; | ||
use Gerardojbaez\Vehicle\Contracts\HasModel as HasModelContract; | ||
use Gerardojbaez\Vehicle\Contracts\HasModelYear as HasModelYearContract; | ||
use Gerardojbaez\Vehicle\Traits\HasMake; | ||
use Gerardojbaez\Vehicle\Traits\HasModel; | ||
use Gerardojbaez\Vehicle\Traits\HasModelYear; | ||
|
||
class Vehicle extends Model implements HasMakeContract, HasModelContract, HasModelYearContract | ||
{ | ||
use HasMake, HasModel, HasModelYear; | ||
``` | ||
|
||
> You do not need to use all traits if you did not use all of them. You can use only `HasMake` trait when only make is used for example. | ||
## Usage | ||
|
||
### The CSV file | ||
|
||
All data is stored in a CSV file. This is done so it's easy to manage. | ||
|
||
File structure: | ||
|
||
| Make | Model | Year | cylinders | displacement | drive | transmission | class | | ||
| --------- | ----------------- | ---- | ---------- | ------------- | ----------------- | ------------------------- | ------------- | | ||
| Acura | ILX | 2017 | 4 | 2.4 | Front-Wheel Drive | 8-Speed Automated Manual | Compact Cars | | ||
|
||
#### Update the CSV file | ||
|
||
Export to the desired location: | ||
|
||
php artisan vehicle:export "/path/to/exported/file.csv" | ||
|
||
When you have done, run: | ||
|
||
php artisan vehicle:generate "/path/to/exported/file.csv" | ||
php artisan db:seed --class VehicleTablesSeeder | ||
|
||
> The `vehicle:generate` command will generate individual files containing its own data to be used with seeders. | ||
>> Remember to `migrate:refresh` if you have prevously seeded the database! | ||
### Models | ||
|
||
This package comes with `Gerardojbaez\Vehicle\Models\VehicleMake`, | ||
`Gerardojbaez\Vehicle\Models\VehicleModel`, | ||
`Gerardojbaez\Vehicle\Models\VehicleModelYear` and | ||
`Gerardojbaez\Vehicle\Models\VehicleOption` models. | ||
|
||
For more information please take a look at each model. | ||
|
||
### Controllers | ||
It's more likely that you will want to retrieve makes, models and years from your frontend (via ajax for example); we have created these basic controllers for you: | ||
`Gerardojbaez\Vehicle\Controllers\MakesController`, | ||
`Gerardojbaez\Vehicle\Controllers\ModelsController`, | ||
`Gerardojbaez\Vehicle\Controllers\ModelYearsController`. You can use these directly or extends with your own. | ||
|
||
Controllers returns a json reponse containing (if any) the requested data. | ||
|
||
#### Routes | ||
|
||
This is an example. You can structure these routes as you want. | ||
|
||
```php | ||
<?php | ||
|
||
// Show make list | ||
Route::get('api/vehicles/makes', [ | ||
'uses' => 'Gerardojbaez\Vehicle\Controllers\MakesController@makes', | ||
'as' => 'api.vehicles.makes' | ||
]); | ||
|
||
// Show make models list | ||
Route::get('api/vehicles/{make}/models', [ | ||
'uses' => 'Gerardojbaez\Vehicle\Controllers\ModelsController@models', | ||
'as' => 'api.vehicles.models' | ||
]); | ||
|
||
// Show model years list | ||
Route::get('api/vehicles/{make}/{model}/years', [ | ||
'uses' => 'Gerardojbaez\Vehicle\Controllers\ModelYearsController@years', | ||
'as' => 'api.vehicles.years' | ||
]); | ||
``` | ||
|
||
## License | ||
|
||
This package is free software distributed under the terms of the MIT license. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "gerardojbaez/vehicle", | ||
"description": "Laravel 5.2 package to work with vehicles data.", | ||
"authors": [ | ||
{ | ||
"name": "Gerardo Báez", | ||
"email": "gerardojbaez@gmail.com" | ||
} | ||
], | ||
"minimum-stability": "dev", | ||
"require": { | ||
"php": ">=5.5.9", | ||
"illuminate/support": "~5.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Gerardojbaez\\Vehicle\\": "src/" | ||
} | ||
} | ||
} |
Oops, something went wrong.