Download the PHP package xloka/generators without Composer

On this page you can find all versions of the php package xloka/generators. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package generators

Forked from JeffreyWay/Laravel-4-Generators.

This package updates the views provided by Jeffrey Way's original works to Material Design Lite. The original documentation from Way's works follows. The instructions have been updated to reflect any changes within this package.

This Laravel 4 package provides a variety of generators to speed up your development process. These generators include:

Prefer a Video Walk-through?

See here.

Installation

Begin by installing this package through Composer. Edit your project's composer.json file to require xloka/generators.

"require": {
    "laravel/framework": "4.0.*",
    "xloka/generators": "dev-master"
},
"minimum-stability" : "dev"

Next, update Composer from the Terminal:

composer update

Once this operation completes, the final step is to add the service provider. Open app/config/app.php, and add a new item to the providers array.

'Xloka\Generators\GeneratorsServiceProvider'

That's it! You're all set to go. Run the artisan command from the Terminal to see the new generate commands.

php artisan

There's also a Sublime Text plugin available to assist with the generators. Definitely use it, but not before you learn the syntax below.

Usage

Think of generators as an easy way to speed up your workflow. Rather than opening the models directory, creating a new file, saving it, and adding the class, you can simply run a single generate command.

Migrations

Laravel 4 offers a migration generator, but it stops just short of creating the schema (or the fields for the table). Let's review a couple examples, using generate:migration.

php artisan generate:migration create_posts_table

If we don't specify the fields option, the following file will be created within app/database/migrations.

Notice that the generator is smart enough to detect that you're trying to create a table. When naming your migrations, make them as description as possible. The migration generator will detect the first word in your migration name and do its best to determine how to proceed. As such, for create_posts_table, the keyword is "create," which means that we should prepare the necessary schema to create a table.

If you instead use a migration name along the lines of add_user_id_to_posts_table, in that case, the keyword is "add," signaling that we intend to add rows to an existing table. Let's see what that generates.

php artisan generate:migration add_user_id_to_posts_table

This will prepare the following boilerplate:

Notice how, this time, we're not doing Schema::create.

Keywords

When writing migration names, use the following keywords to provide hints for the generator.

Generating Schema

This is pretty nice, but let's take things a step further and also generate the schema, using the fields option.

php artisan generate:migration create_posts_table --fields="title:string, body:text"

Before we decipher this new option, let's see the output:

Nice! A few things to notice here:

To declare fields, use a comma-separated list of key:value:option sets, where key is the name of the field, value is the column type, and option is a way to specify indexes and such, like unique or nullable. Here are some examples:

Please make note of the last example, where we specify a character limit: string[30]. This will produce $table->string('username', 30)->unique();

It is possible to destroy the table by issuing:

php artisan generate:migration destroy_posts_table

If you'd like to have an accurate artisan rollback option set the fields option as well:

php artisan generate:migration destroy_posts_table --fields="title:string, body:text"

As a final demonstration, let's run a migration to remove the completed field from a tasks table.

php artisan generate:migration remove_completed_from_tasks_table --fields="completed:boolean"

This time, as we're using the "remove" keyword, the generator understands that it should drop a column, and add it back in the down() method.

Models

php artisan generate:model Post

This will create the file, app/models/Post.php and insert the following boilerplate:

Views

php artisan generate:view dog

This command will generate app/views/dog.blade.php and a simple string, for convenience.

The dog.blade.php view.

As with all of the commands, you may specify a --path option to place this file elsewhere.

php artisan generate:view index --path=views/dogs

Now, we get: app/views/dogs/index.blade.php.

Seeds

Laravel 4 provides us with a flexible way to seed new tables.

php artisan generate:seed dogs

Set the argument to the name of the table that you'd like a seed file for. This will generate app/database/seeds/DogsTableSeeder.php and populate it with:

This command will also update app/database/seeds/DatabaseSeeder.php to include a call to this new seed class, as required by Laravel.

To fully seed the dogs table:

Resources

Think of the resource generator as the big enchilada. It calls all of its sibling generate commands. Assuming the following command:

php artisan generate:resource dog --fields="name:string"

The following actions will take place:

Please note that the resource name is singular - the same as how you would name your model.

Workflow

Let's create a resource for displaying dogs in a restful way.

php artisan generate:resource dog --fields="name:string, age:integer"

Next, we'll seed this new dogs table. Open database/seeds/DogsTableSeeder.php and add a couple of rows. Remember, you only need to edit the $dogs array within this file.

$dogs = [
    ['name' => 'Sparky', 'age' => 5],
    ['name' => 'Joe', 'age' => 11]
];

Now, we migrate the database and seed the dogs table.

php artisan migrate
php artisan db:seed

Finally, let's display these two dogs, when accessing the dogs/ route. Edit controllers/DogsController.php, and update the index method, like so:

public function index()
{
    return View::make('dogs.index')
        ->with('dogs', Dog::all());
}

The last step is to update the view to display each of the posts that was passed to it. Open views/dogs/index.blade.php and add:

<ul>
    @foreach($dogs as $dog)
        <li>{{ $dog->name }} : {{ $dog->age }}</li>
    @endforeach
</ul>

Okay, okay, we're not using a layout file with the proper HTML. Who cares; this is just an example, fool.

Anyhow, we're all set. Run the server, and browse to localhost:8000/dogs to view your list.

php artisan serve

Isn't that way faster than manually doing all of that writing? To finish up, let's run the tests to make sure that everything is working, as expected.

phpunit

And...it's green!

Scaffolding

scaffolding

Think of scaffolding as an extension of a resource. It has the exact same interface.

The only difference is that it will handle all of the boilerplate. This can be particularly useful for prototyping - or even learning how to do basic things, such as delete a record from a database table, or build a form, or perform validation on that form.

view scaffold

view validation

Forms

This handy new generator allows you to, with a single command, generate the necessary HTML for a form, based on attributes from a provided model. Perhaps an example is in order:

Assuming that I do have a Tweet model and its associated tweet table, this command will output:

Pretty neat, huh? It read the attributes and data types, and prepared the markup for you! One less thing to worry about!

Specifying the Form's Method

But what if you intend to update a resource, rather than create a new one? Well, in that case, use the --method option.

This will mostly generate the same HTML, however, the Form::open() method will be adjusted, as needed:

The method option will accept any number of values (add, edit, update, post, create, etc.), but, essentially, you're just telling it whether you are creating or editing a resource. As such, there's only two possible outputs: POST and PATCH (the former being the default).

Custom HTML

What if you don't like the idea of using an unordered list for a form? Use the --html option, along with the name of the element that you'd prefer to use:

Now, the generator we'll present the elements within divs!

Copying and Saving

At least for now, and unlike the other generators in this package, this command will output the form, at which point you can copy and paste it where needed. Of course, you can always pipe the output to the clipboard or save to a file, using existing tools. For instance:

Tests

Use generate:test when you need to create a new PHPUnit test class. Here's an example:

This will produce app/tests/FooTest.php.

Pivot Tables

Creating joinable/pivot tables can sometimes be confusing.

This process can be automated now. Simply call the generate:pivot command, and provide the names of the tables that should be joinable. For example, a post can have many tags, and a tag can have many posts. Run the following command to create the necessary pivot table.

It doesn't matter which order you provide the table names (or whether you pluralize them or not). The command will correctly create a post_tag migration that has post_id and tag_id fields.

Finally, simply migrate the database to create it.

Pivot table finished!

To put it all together, let's do it from scratch. We need a posts table, a tags table, and the connecting pivot table for the two. We can tackle this easily with the generators.


All versions of generators with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
mustache/mustache Version 2.4.*
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package xloka/generators contains the following files

Loading the files please wait ....