flipboxstudio / lumen-generator

A Lumen Generator You Are Missing
https://packagist.org/packages/flipbox/lumen-generator
MIT License
824 stars 126 forks source link

Add make:cast command #99

Closed jorgemudry closed 3 years ago

jorgemudry commented 3 years ago

What does this Pull Request Do?

It adds the make:cast command.

How should this be manually tested?

  1. Add the fork to your composer.json file:
    "require": {
        "php": "^7.3|^8.0",
        "laravel/lumen-framework": "^8.0",
        "flipbox/lumen-generator": "dev-feature_add_make_cast_command"
    },
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/jorgemudry/lumen-generator"
        }
    ]
  1. Install the package:
$ composer update flipbox/lumen-generator;
  1. Use the make:cast command:
$ php artisan make:cast MyCast
  1. You should end up with a MyCast.php class in your app/Casts directory looking like this:
<?php

namespace App\Casts;

use Illuminate\Contracts\Database\Eloquent\CastsAttributes;

class MyCast implements CastsAttributes
{
    /**
     * Cast the given value.
     *
     * @param  \Illuminate\Database\Eloquent\Model  $model
     * @param  string  $key
     * @param  mixed  $value
     * @param  array  $attributes
     * @return mixed
     */
    public function get($model, $key, $value, $attributes)
    {
        return $value;
    }

    /**
     * Prepare the given value for storage.
     *
     * @param  \Illuminate\Database\Eloquent\Model  $model
     * @param  string  $key
     * @param  array  $value
     * @param  array  $attributes
     * @return mixed
     */
    public function set($model, $key, $value, $attributes)
    {
        return $value;
    }
}

Any background context you want to provide?

N/A

Any extra info?

excited