Skip to content

Commit

Permalink
Working on documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Dec 10, 2013
1 parent a562e39 commit 5390216
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 1 deletion.
4 changes: 4 additions & 0 deletions commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ When creating the command, the `--command` option may be used to assign the term

php artisan command:make AssignUsers --command=users:assign

If you need to create a command for a [workbench package](/docs/packages), use the `--bench` switch:

php artisan command:make AssignUsers --bench="vendor/package"

### Writing The Command

Once your command is generated, you should fill out the `name` and `description` properties of the class, which will be used when displaying your command on the `list` screen.
Expand Down
1 change: 1 addition & 0 deletions documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- [Queues](/docs/queues)
- [Security](/docs/security)
- [Session](/docs/session)
- [SSH](/docs/ssh)
- [Templates](/docs/templates)
- [Unit Testing](/docs/testing)
- [Validation](/docs/validation)
Expand Down
30 changes: 30 additions & 0 deletions eloquent.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ If you are unable to generate the query you need via the fluent interface, feel

$users = User::whereRaw('age > ? and votes = 100', array(25))->get();

**Chunking Results**

If you need to process a lot (thousands) of Eloquent records, using the `chunk` command will allow you to do without eating all of your RAM:

User::chunk(200, function($users)
{
foreach ($users as $user)
{
//
}
});

The first argument passed to the method is the number of records you wish to receive per "chunk". The Closure passed as the second argument will be called for each chunk that is pulled from the database.

**Specifying The Query Connection**

You may also specify which database connection should be used when running an Eloquent query. Simply use the `on` method:
Expand Down Expand Up @@ -168,8 +182,15 @@ After saving or creating a new model that uses auto-incrementing IDs, you may re

**Using The Model Create Method**

// Create a new user in the database...
$user = User::create(array('name' => 'John'));

// Retrieve the user by the attributes, or create it if it doesn't exist...
$user = User::firstOrCreate(array('name' => 'John'));

// Retrieve the user by the attributes, or instantiate a new instance...
$user = User::firstOrNew(array('name' => 'John'));

To update a model, you may retrieve it, change an attribute, and use the `save` method:

**Updating A Retrieved Model**
Expand Down Expand Up @@ -780,6 +801,15 @@ To delete all records on the pivot table for a model, you may use the `detach` m

Note that this operation does not delete records from the `roles` table, but only from the pivot table.

**Defining A Custom Pivot Model**

Laravel also allows you to define a custom Pivot model. To define a custom model, first create your own "Base" model class that extends `Eloquent`. In your other Eloquent models, extend this custom base model instead of the default `Eloquent` base. In your base model, add the following function that returns an instance of your custom Pivot model:

public function newPivot(Model $parent, array $attributes, $table, $exists)
{
return new YourCustomPivot($parent, $attributes, $table, $exists);
}

<a name="collections"></a>
## Collections

Expand Down
6 changes: 6 additions & 0 deletions pagination.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- [Configuration](#configuration)
- [Usage](#usage)
- [Appending To Pagination Links](#appending-to-pagination-links)
- [Converting To JSON](#converting-to-json)

<a name="configuration"></a>
## Configuration
Expand Down Expand Up @@ -76,3 +77,8 @@ You can add to the query string of pagination links using the `appends` method o
This will generate URLs that look something like this:

http://example.com/something?page=2&sort=votes

<a name="converting-to-json"></a>
## Converting To JSON

The `Paginator` class implements the `Illuminate\Support\Contracts\JsonableInterface` contract and exposes the `toJson` method. You can may also convert a `Paginator` instance to JSON by returning it from a route. The JSON'd form of the instance will include some "meta" information such as `total`, `current_page`, `last_page`, `from`, and `to`. The instance's data will be available via the `data` key in the JSON array.
12 changes: 11 additions & 1 deletion queues.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ If you want the job to use a method other than `fire`, you may specify the metho

Queue::push('SendEmail@send', array('message' => $message));

If you need to pass the same data to several queue jobs, you may use the `Queue::bulk` method:

**Passing The Same Payload To Multiple Jobs**

Queue::bulk(array('SendEmail', 'NotifyUser'), $payload);

Sometimes you may wish to delay the execute of a queued job. For instance, you may wish to queue a job that sends a customer an e-mail 15 minutes after sign-up. You can accomplish this using the `Queue::later` method:

**Delaying The Execution Of A Job**
Expand Down Expand Up @@ -139,14 +145,18 @@ You may also set the length of time (in seconds) each job should be allowed to r

php artisan queue:listen --timeout=60

**Specifying Queue Sleep Duration**

In addition, you may specify the number of seconds to wait before polling for new jobs:

php artisan queue:listen --sleep=5

To process only the first job on the queue, you may use the `queue:work` command:
Note that the queue only "sleeps" if no jobs are on the queue. If more jobs are available, the queue will continue to work them without sleeping.

**Processing The First Job On The Queue**

To process only the first job on the queue, you may use the `queue:work` command:

php artisan queue:work

<a name="push-queues"></a>
Expand Down
4 changes: 4 additions & 0 deletions responses.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@ The second argument passed to `View::make` is an array of data that should be ma

**Passing Data To Views**

// Using conventional approach
$view = View::make('greeting')->with('name', 'Steve');

// Using Magic Methods
$view = View::make('greeting')->withName('steve');

In the example above the variable `$name` would be accessible from the view, and would contain `Steve`.

If you wish, you may pass an array of data as the second parameter given to the `make` method:
Expand Down
70 changes: 70 additions & 0 deletions ssh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# SSH

- [Configuration](#configuration)
- [Basic Usage](#basic-usage)
- [Tasks](#tasks)
- [SFTP Uploads](#sftp-uploads)

<a name="configuration"></a>
## Configuration

Laravel includes a simple way to SSH into remote servers and run commands, allowing you to easily build Artisan tasks that work on remote servers. The `SSH` facade provides the access point to connecting to your remote servers and running commands.

The configuration file is located at `app/config/remote.php`, and contains all of the options you need to configure your remote connections. The `connections` array contains a list of your servers keyed by name. Simple populate the credentials in the `connections` array and you will be ready to start running remote tasks. Note that the `SSH` can authenticate using either a password or an SSH key.

<a name="basic-usage"></a>
## Basic Usage

**Running Commands On The Default Server**

To run commands on your `default` remote connection, use the `SSH::run` method:

SSH::run(array(
'cd /var/www',
'git pull origin master',
));

**Running Commands On A Specific Connection**

Alternatively, you may run commands on a specific connection using the `into` method:

SSH::into('staging')->run(array(
'cd /var/www',
'git pull origin master',
));

**Catching Output From Commands**

You may catch the "live" output of your remote commands by passing a Closure into the `run` method:

SSH::run($commands, function($line)
{
echo $line.PHP_EOL;
});

## Tasks
<a name="tasks"></a>

If you need to define a group of commands that should always be run together, you may use the `define` method to define a `task`:

SSH::into('staging')->define('deploy', array(
'cd /var/www',
'git pull origin master',
'php artisan migrate',
));

Once the task has been defined, you may use the `task` method to run it:

SSH::into('staging')->task('deploy', function($line)
{
echo $line.PHP_EOL;
});

<a name="sftp-uploads"></a>
## SFTP Uploads

The `SSH` class also includes a simple way to upload files, or even strings, to the server using the `put` and `putString` methods:

SSH::into('staging')->put($localFile, $remotePath);

SSH::into('staging')->putString('Foo', $remotePath);
9 changes: 9 additions & 0 deletions testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ Laravel ships with several `assert` methods to make testing a little easier:
$this->assertSessionHas('age', $value);
}

**Asserting Old Input Has Some Data**

public function testMethod()
{
$this->call('GET', '/');

$this->assertHasOldInput();
}

<a name="helper-methods"></a>
## Helper Methods

Expand Down

0 comments on commit 5390216

Please sign in to comment.