Skip to content

Commit

Permalink
prepare for release
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Sep 26, 2018
1 parent b987a23 commit 1e7cadf
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `laravel-view-models` will be documented in this file

## 1.1.0 - 2018-09-26

- Add a `make:view-model` command

## 1.0.2 - 2018-09-12

- Properly ignore magic methods
Expand Down
43 changes: 19 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,6 @@ You can install the package via composer:
composer require spatie/laravel-view-models
```

For Laravel versions 5.5+, the ServiceProvider will be automatically discovered.
Otherwise, add to `config/app.php`, under `providers` key:

```php
'providers' => [
(...)
/*
* Package Service Providers...
*/
\Spatie\ViewModels\Providers\ViewModelsServiceProvider::class,
```

To generate a new ViewModel, into `App\ViewModels` namespace:

```bash
php artisan make:view-model HomepageViewModel
```

or into a custom namespace, say, `App\Blog`

```bash
php artisan make:view-model Blog/PostsViewModel
```

## Usage

A view model is a class where you can put some complex logic for your views. This will make your controllers a bit lighter. You can create a view model by extending the provided `Spatie\ViewModels\ViewModel`.
Expand Down Expand Up @@ -183,6 +159,25 @@ You can use these functions in the view like so:
{{ $formatDate($post->created_at) }}
```

### Making a new view model

The package included an artisan command to create a new view model.

```bash
php artisan make:view-model HomepageViewModel
```

This view model will have the `App\ViewModels` namespace and will be saved in `app/ViewModels`.

or into a custom namespace, say, `App\Blog`

```bash
php artisan make:view-model "Blog/PostsViewModel"
```

This view model will have the `App\Blog\ViewModels` namespace and will be saved in `app/Blog/ViewModels`.


### Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
}
],
"require": {
"php": "^7.1"
"php": "^7.1",
"illuminate/support": "~5.5|~5.6|~5.7"
},
"require-dev": {
"orchestra/testbench": "^3.7",
"orchestra/testbench": "~3.5|~3.6|~3.7",
"phpunit/phpunit": "^7.3"
},
"autoload": {
Expand Down
4 changes: 2 additions & 2 deletions tests/ViewModelMakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class ViewModelMakeCommandTest extends TestCase
{
/** @test */
public function creates_file_in_default_folder()
public function it_can_create_a_view_model()
{
$exitCode = Artisan::call('make:view-model', [
'name' => 'HomeViewModel',
Expand All @@ -31,7 +31,7 @@ public function creates_file_in_default_folder()
}

/** @test */
public function creates_file_in_custom_folder()
public function it_can_create_a_view_model_with_a_custom_namespace()
{
$exitCode = Artisan::call('make:view-model', [
'name' => 'Blog/PostsViewModel',
Expand Down

0 comments on commit 1e7cadf

Please sign in to comment.