Browse files

Fixing migration names, updating bundle file, updating README

  • Loading branch information...
1 parent e32da66 commit 75af8d6e07da865a1e9c20ebedba7dcf3dae846f @vespakoen committed Jan 30, 2012
View
99 README.md
@@ -9,26 +9,90 @@ All credits go to machuga for PHP-izing this awesome library
## NOTE
- This bundle is not (yet) available via artisan.
-- You can use this migration to setup the database tables: https://github.com/Vespakoen/ShopHub/blob/develop/application/migrations/2012_01_24_1327455253_add_authority_tables.php
- And lastly, Unlike the Codeigniter Authorization library, "Users" and "Roles" have "has_and_belongs_to_many" relations.
## Configuration
+### Setup the bundle
+
+#### Setting up Laravel
+
+- Enter you Database settings in config/database.php
+- Enter a key (minimum length 32 chars) in config/application.php
+- Enter a session driver in config/session.php
+- Change the value of 'inflection' in config/strings.php to the one below this line
+```
+'inflection' => array(
+
+ 'user' => 'users',
+ 'role' => 'roles',
+
+),
+```
+
+#### Loading the bundle
+
+In order to use the bundle you have to add it to the `bundles/bundles.php` file.
+It should look similar to this:
+
+```
+return array(
+ 'eloquent' => array(
+ 'location' => 'eloquent'
+ ),
+ 'authority' => array(
+ 'location' => 'authority-laravel',
+ 'auto' => true
+ )
+);
+```
+
+
+#### Setting up Eloquent & Migrations
+
+If you already have the Eloquent bundle installed you can skip this step.
+To install Eloquent, use the `cd` command to go to your laravel directory, now run the following commands:
+
+`php artisan bundle:install eloquent`
+
+`php artisan migrate:install`
+
+`php artisan migrate`
+
+
+#### Configure Auth config
+
+By default laravels' auth is configured without Eloquent. to enable this, replace the methods in config/auth.php with the ones below.
+
+```php
+'user' => function($id)
+{
+ if (filter_var($id, FILTER_VALIDATE_INT) !== false)
+ {
+ return User::find($id);
+ }
+},
+
+'attempt' => function($username, $password)
+{
+ $user = User::where_username($username)->first();
+
+ if ( ! is_null($user) and Hash::check($password, $user->password))
+ {
+ return $user;
+ }
+},
+```
+
### Setup your Models
-#### User model
+#### User model (models/user.php)
```PHP
class User extends Eloquent\Model {
public static $timestamps = true;
- public $rules = array(
- 'email' => 'required|email',
- 'password' => 'required',
- 'name' => 'required',
- );
-
public function roles()
{
return $this->has_and_belongs_to_many('Role');
@@ -68,7 +132,7 @@ class User extends Eloquent\Model {
```
-#### Role model
+#### Role model (models/role.php)
```PHP
class Role extends Eloquent\Model {
@@ -80,21 +144,8 @@ class Role extends Eloquent\Model {
}
```
-
-### Add Authority to the Autoloader
-
-open up config/application.php and add Authority to the `bundles` config, it should look similar to this
-
-```
- 'bundles' => array(
- 'Authority'
- ),
-```
-
-
### Setting up Rules
-Modify `bundles/authority/config/authority.php` to your likings
-
+Modify `bundles/authority/config/authority.php` to your likings, more info on how to do this can be found at https://github.com/machuga/codeigniter-authority-authorization
-# Done!
+# Congrats... Done!
View
2 bundle.php
@@ -1,4 +1,4 @@
<?php
Laravel\Autoloader::map(array(
- 'Authority' => path('bundle').'authority/authority'.EXT,
+ 'Authority' => path('bundle').'authority-laravel/authority'.EXT,
));
View
16 ...tions/2012_01_24_add_authority_tables.php → ...012_01_24_205457_add_authority_tables.php
@@ -1,14 +1,14 @@
<?php
-class Add_Authority_Tables {
+class Authority_add_authority_tables {
public function up()
{
Schema::table('users', function($table)
{
$table->create();
$table->increments('id');
- $table->string('email')->unique();
+ $table->string('email');
$table->string('password');
$table->string('name');
$table->timestamp('created_at');
@@ -19,17 +19,7 @@ public function up()
{
$table->create();
$table->increments('id');
- $table->string('key')->unique();
- });
-
- Schema::table('role_lang', function($table)
- {
- $table->create();
- $table->increments('id');
- $table->integer('role_id');
- $table->integer('language_id');
- $table->string('name');
- $table->string('description');
+ $table->string('key');
});
Schema::table('roles_users', function($table)
View
6 ..._01_26_add_language_id_to_users_table.php → ...205457_add_language_id_to_users_table.php
@@ -1,6 +1,6 @@
<?php
-class Add_Language_Id_To_Accounts_Table {
+class Authority_add_language_id_to_users_table {
/**
* Make changes to the database.
@@ -9,7 +9,7 @@ class Add_Language_Id_To_Accounts_Table {
*/
public function up()
{
- Schema::table('accounts', function($table)
+ Schema::table('users', function($table)
{
$table->integer('language_id')->default('1');
});
@@ -22,7 +22,7 @@ public function up()
*/
public function down()
{
- Schema::table('accounts', function($table)
+ Schema::table('users', function($table)
{
$table->drop_column('language_id');
});

0 comments on commit 75af8d6

Please sign in to comment.