1 頁 (共 1 頁)

frozennode/administrator

發表於 : 2015-03-08 09:30:53
yehlu
Laravel Administrator
Administrator is an administrative interface builder for Laravel. With Administrator you can visually manage your Eloquent models and their relations, and also create stand-alone settings pages for storing site data and performing site tasks.

Author: Jan Hartigan
Website: http://frozennode.com
Version: 5.0.1
Build Status



Composer

To install Administrator as a Composer package to be used with Laravel 5, simply add this to your composer.json:

"frozennode/administrator": "5.*"
..and run composer update. Once it's installed, you can register the service provider in config/app.php in the providers array:

'providers' => [
'Frozennode\Administrator\AdministratorServiceProvider',
]
Then publish Administrator's assets with php artisan vendor:publish. This will add the file config/administrator.php. This config file is the primary way you interact with Administrator. This command will also publish all of the assets, views, and translation files.

Laravel 4

If you want to use Administrator with Laravel 4, you need to resolve to Administrator 4:

"frozennode/administrator": "4.*"
Then publish the config file with php artisan config:publish frozennode/administrator. This will add the file app/config/packages/frozennode/administrator/administrator.php.

Then finally you need to publish the package's assets with the php artisan asset:publish frozennode/administrator command.

Laravel 3

Since Administrator has switched over to Composer, you can no longer use php artisan bundle:install administrator or php artisan bundle:upgrade administrator. If you want to use Administrator with Laravel 3, you must switch to the 3.3.2 branch, download it, and add it in the /bundles/administrator directory and add this to your bundles.php file:

'administrator' => array(
'handles' => 'admin', //this determines what URI this bundle will use
'auto' => true,
),
Documentation

The complete docs for Administrator can be found at http://administrator.frozennode.com. You can also find the docs in the /src/docs directory.

Copyright and License

Administrator was written by Jan Hartigan of Frozen Node for the Laravel framework. Administrator is released under the MIT License. See the LICENSE file for details.

Recent Changelog

5.0.1

Bugfix: Fixing csrf token mismatches for some requests
5.0.0

Upgraded to Laravel 5
New translations (az)

Re: frozennode/administrator

發表於 : 2015-03-08 09:31:16
yehlu
for laravel 4.x

composer.json
"frozennode/administrator": "dev-master"

composer update


app/config/app.php
providers
'Frozennode\Administrator\AdministratorServiceProvider',

XXXphp artisan asset:publish frozennode/administrator

php artisan config:publish frozennode/administrator

app/config/packages/frozennode/administrator/administrator.php

vi app/config/packages/frozennode/administrator/administrator.php

代碼: 選擇全部

 'title' => 'BNI',
  'menu' => array('new_company'),'
 'permission'=> function()
        {
                //return Auth::check();
                return true;
        },
mkdir app/config/administrator
mkdir app/config/administrator/settings

app/config/administrator/new_company.php

代碼: 選擇全部

<?php

/**
 *
 */
return array(
	'title' => 'NewCompany',
	'single' => 'Company',
	'model' => 'NewCompany',
	/**
	 * The display columns
	 */
	'columns' => array(
		'id',
		'month',
		'sn',
		'tax_id',
		'company',
		'addr',
		'owner',
		'amount',
		'date',
	),
	/**
	 * The filter set
	 */

	'filters' => array(
		'id',
		'month',
		'sn',
		'tax_id',
		'company',
		'addr',
		'owner',
		'amount',
		'date',
	),

	/**
	 * The editable fields
	 */

	'edit_fields' => array(
		'id',
		'month',
		'sn',
		'tax_id',
		'company',
		'addr',
		'owner',
		'amount',
		'date',
	),
/*
'before_save' => function(&$data){
return "Sorry, can't be saved";
$data['site_name'] = $data['site_name'] . ' - The Blurst Site Ever';
},
 */
	'action_permissions' => array(
		'update' => function ($model) {
			return false;
		},
		'delete' => function ($model) {
			return false;
		},
	),

);
app/models/NewCompany.php

代碼: 選擇全部

<?php

class NewCompany extends Eloquent {

    protected $table = 'new_company';

    protected $fillable = array('id','month','sn','tax_id','company','addr','owner','amount','date');

}

Re: frozennode/administrator

發表於 : 2015-12-06 20:30:42
yehlu
Laravel 5.x

composer.json

代碼: 選擇全部

        "frozennode/administrator": "5.*"
config/app.php

代碼: 選擇全部

		Frozennode\Administrator\AdministratorServiceProvider::class,
php artisan vendor:publish

mkdir config/administrator
mkdir config/administrator/settings

config\administrator.php

代碼: 選擇全部

	'title' => 'Admin',
	'menu' => array('user'),
        'home_page' => 'user',
	'permission' => function () {
		//return Auth::check();
		return true;
	},
app\User.php

代碼: 選擇全部

<?php

namespace App;

use Illuminate\Auth\Authenticatable;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\Access\Authorizable;

class User extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract {
	use Authenticatable, Authorizable, CanResetPassword;

	/**
	 * The database table used by the model.
	 *
	 * @var string
	 */
	protected $table = 'users';

	/**
	 * The attributes that are mass assignable.
	 *
	 * @var array
	 */
	protected $fillable = ['name', 'email', 'password'];

	/**
	 * The attributes excluded from the model's JSON form.
	 *
	 * @var array
	 */
	protected $hidden = ['password', 'remember_token'];
}

config\administartor\user.php

代碼: 選擇全部

<?php

/**
 *
 */
return array(
	'title' => 'User',
	'single' => 'User',
	'model' => 'App\User',
	/**
	 * The display columns
	 */
	'columns' => array(
		'id',
		'name',
		'email',
		'password',
	),
	/**
	 * The filter set
	 */

	'filters' => array(
		'id',
		'name',
		'email',
	),

	/**
	 * The editable fields
	 */

	'edit_fields' => array(
		'id',
		'name',
		'email',
		'password',
	),

	'before_save' => function (&$data) {
		$data['password'] = Hash::make($data['password']);
	},

	'action_permissions' => array(
		'update' => function ($model) {
			//return false;
			return true;
		},
		'delete' => function ($model) {
			return false;
		},
	),

);

Re: frozennode/administrator

發表於 : 2015-12-12 21:47:35
yehlu
新增欄位

php artisan make:migration create_prods_table --table=prods

代碼: 選擇全部

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateProdsTable extends Migration {
	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up() {
		Schema::create('prods', function (Blueprint $table) {
			$table->increments('id');
			$table->string('barcode');
			$table->string('prod');
			$table->timestamps();
		});
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down() {
		Schema::drop('prod');
	}
}


Relationship

發表於 : 2015-12-13 07:50:58
yehlu
app/Models/Prod.php

代碼: 選擇全部

    public function stockcheck()
    {
        return $this->hasMany('App\Models\StockCheck');
    }
app/Model/Stock.php

代碼: 選擇全部

    public function stockcheck()
    {
        return $this->hasMany('App\Models\StockCheck');
    }
}
app/Models/StockCheck.php

代碼: 選擇全部

    public function stock()
    {
        return $this->belongsTo('App\Models\Stock');
    }

    public function prod()
    {
        return $this->belongsTo('App\Models\Prod');
    }
config/administrator/stockcheck.php

代碼: 選擇全部

<?php

/**
 *
 */
return array(
    'title' => 'StockCheck',
    'single' => 'StockCheck',
    'model' => 'App\Models\StockCheck',
    /**
     * The display columns
     */
    'columns' => array(
        'id',
        'stock_id' => array(
            'title' => "stock",
            'relationship' => 'stock', //this is the name of the Eloquent relationship method!
            'select' => "(:table).stock",
        ),
        'prod_id',
        'prod' => array(
            'title' => "prod",
            'relationship' => 'prod', //this is the name of the Eloquent relationship method!
            'select' => "(:table).prod",
        ),
        'stocks',
        'stock_check_no',
    ),
    /**
     * The filter set
     */

    'filters' => array(
        'id',
        'stock_id',
        'stock' => array(
            'type' => 'relationship',
            'title' => 'Stock',
            'name_field' => 'stock',
        ),
        'prod_id',
        'stock_id',
        'prod' => array(
            'type' => 'relationship',
            'title' => 'Prod',
            'name_field' => 'prod',
        ),
        'stock_check_no',
    ),

    /**
     * The editable fields
     */

    'edit_fields' => array(
        'id',
        'stock' => array(
            'type' => 'relationship',
            'title' => 'Stock',
            'name_field' => 'stock',
        ),
        'prod' => array(
            'type' => 'relationship',
            'title' => 'Prod',
            'name_field' => 'prod',
        ),
        'stocks',
        'stock_check_no',
    ),

    'action_permissions' => array(
        'update' => function ($model) {
            //return false;
            return true;
        },
        'delete' => function ($model) {
            return false;
        },
    ),

);


Re: frozennode/administrator

發表於 : 2015-12-14 19:40:07
yehlu
https://github.com/FrozenNode/Laravel-A ... issues/503

Setter Option

The setter option lets you define a field as an attribute that is set on the Eloquent model, but is unset before the model is saved. This gives you access to use it as a mutator without having to worry about that value getting stored in the database. By default, this is set to false for all fields except for the password field.

https://laravel.tw/docs/5.1/eloquent-mutators
異動前變更資料
或取出資料後變更

app\Models\User.php
app\User.php

代碼: 選擇全部

	public function setPassWordAttribute($value) {
		$this->attributes['password'] = \Hash::make($value);
	}

Re: frozennode/administrator

發表於 : 2015-12-14 20:20:55
yehlu
填入新增與異動人員
config/administrator/user.php

代碼: 選擇全部


    'edit_fields' => array(
        'id',
        'stock',
        'key_user' => array(
            'title' => 'Key User',
            'editable' => function ($model) {
                return !$model->exists; //will only be editable before an item is saved for the first time
            },
        ),
        'mod_user' => array(
            'title' => 'Mod User',
            'editable' => function ($model) {
                return !$model->exists; //will only be editable before an item is saved for the first time
            },
        ),
    ),
model

代碼: 選擇全部


    public function setKeyUserAttribute($value)
    {
        if (substr(\Request::path(), -3) == 'New') {
            $this->attributes['key_user'] = \Auth::user()->id;
        }
    }

	public function setModUserAttribute($value) {
		$this->attributes['Mod_user'] =  \Auth::user()->id;
	}


Re: frozennode/administrator

發表於 : 2015-12-16 14:01:40
yehlu
圖片上傳

edit_fields

代碼: 選擇全部

        'prod_jpg' => array(
            'title' => 'Image',
            'type' => 'image',
            'location' => public_path() . '/uploads/products/originals/',
            'naming' => 'random',
            'length' => 20,
            'size_limit' => 2,
            'sizes' => array(
                array(65, 57, 'crop', public_path() . '/uploads/products/thumbs/small/', 100),
                array(220, 138, 'landscape', public_path() . '/uploads/products/thumbs/medium/', 100),
                array(383, 276, 'fit', public_path() . '/uploads/products/thumbs/full/', 100),
            ),
        ),
columns

代碼: 選擇全部

        'prod_jpg' => array(
            'title' => 'Prod Images',
            'output' => function ($value) {
                if ($value != "") {
                    return '<img src="/uploads/products/thumbs/small/' . $value . '" height="65" />';
                } else {
                    return "";
                }
            },
        ),

代碼: 選擇全部

'banner_image' => array(
    'title' => 'Banner Image',
    'output' => '<img src="/uploads/collections/resize/(:value)" height="100" />',
),

Re: frozennode/administrator

發表於 : 2016-05-28 16:34:06
yehlu
無法使用原因

osx apache2 的 mod_rewrite 沒打開
administrator 的資料夾不能有不需要的檔案
dickson 做的自動產生 config 有 Model 的名稱多了s 及沒有用 "駝峰式命名規則"

Laravel-Administrator and Laravel 5.2 Auth

發表於 : 2016-07-05 16:40:19
yehlu

增加帳號是否啟用

發表於 : 2016-07-05 18:09:16
yehlu
migrate

代碼: 選擇全部

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class AddUsersClose extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //
        Schema::table('users', function (Blueprint $table) {
            //
            $table->char('close', 1)->default('Y')->comment('停用');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
        Schema::table('users', function (Blueprint $table) {
            //
            $table->dropColumn('close');
        });
    }
}

config/administrator.php

代碼: 選擇全部

    'permission' => function () {
        if (Auth::check()) {
            $close = Auth::user()->close;
            if ($close == 'N') {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
//        return Auth::check();
        //        return true;
    },

Laravel 5.2 Auth

發表於 : 2016-08-05 16:58:18
yehlu
administrator.php

代碼: 選擇全部

  'middleware' => ['web'],

export excel

發表於 : 2016-09-25 11:11:57
yehlu

代碼: 選擇全部

https://laracasts.com/index.php/discuss/channels/general-discussion/laravel-administrator-and-laravel-excel?page=1

代碼: 選擇全部

    'global_actions' => array(
        'export_to_excel' => array(
            'title' => 'Export To Excel',
            'messages' => array(
                'active' => 'Exporting...',
                'success' => 'Spreadsheet created!',
                'error' => 'There was an error while creating this spreadsheet',
            ),
            'action' => function ($query) {
                //get all the rows for this query
                $data = $query->get();

                //do something to put it into excel

                Excel::create('classess', function ($excel) use ($data) {

                    // Set sheets
                    $excel->sheet('first sheet', function ($sheet) use ($data) {

                        // Sheet manipulation
                        $sheet->fromArray($data);
                    });

                })->store('csv', storage_path('excel/exports'), true);
                $pathToFile = storage_path('excel/exports').'/classess.csv';
                return response()->download($pathToFile);
            },
        ),


Re: frozennode/administrator default value

發表於 : 2016-10-14 11:45:24
yehlu
app/Providers/AppServiceProvider.php

代碼: 選擇全部

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Auth;
use App\Models\Prod24hpchome;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
        Prod24hpchome::creating(function ($Prod24hpchome) {
            $Prod24hpchome->key_user = \Auth::user()->id;
            $Prod24hpchome->mod_user = \Auth::user()->id;
            $Prod24hpchome->close = '0';   
        });
        Prod24hpchome::updating(function ($Prod24hpchome) {
            $Prod24hpchome->mod_user = \Auth::user()->id;
        });
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
        if ($this->app->environment() == 'local') {
            $this->app->register('Iber\Generator\ModelGeneratorProvider');
            $this->app->register('Barryvdh\Debugbar\ServiceProvider');
        }
    }
}