<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6534406401424841087</id><updated>2026-03-09T03:55:44.241+08:00</updated><category term="php"/><category term="laravel"/><category term="javascript"/><category term="sublime"/><category term="artisan"/><category term="es6"/><category term="git"/><category term="standalone"/><category term="__call"/><category term="css"/><category term="jquery"/><category term="mysql"/><category term="socialite"/><category term="terminal"/><category term="utf8"/><category term="遠振"/><category term="5.0.2"/><category term="Symfony"/><category term="TimelineMax"/><category term="apache"/><category term="application"/><category term="async"/><category term="atom"/><category term="babel"/><category term="babel6"/><category term="blade"/><category term="co"/><category term="coffeescript"/><category term="composer"/><category term="composite"/><category term="constructor"/><category term="database"/><category term="debug"/><category term="decorator"/><category term="defineProperty"/><category term="disable exec"/><category term="editor"/><category term="eloquent"/><category term="escapeshellarg"/><category term="extends"/><category term="facade root"/><category term="facebook"/><category term="file extension"/><category term="freetds"/><category term="generator"/><category term="guzzle"/><category term="less"/><category term="linux"/><category term="mac"/><category term="mock"/><category term="mssql"/><category term="nodejs"/><category term="osx"/><category term="php-cgi"/><category term="php-cli"/><category term="phpcs"/><category term="phpunit"/><category term="promise"/><category term="prototype"/><category term="repository"/><category term="schedule"/><category term="session"/><category term="super"/><category term="syncing"/><category term="taiwan"/><category term="template"/><category term="timezone"/><category term="tinymce"/><category term="tracy"/><category term="twzipcode"/><category term="ubuntu"/><category term="view"/><category term="virtualbox"/><category term="wampserver"/><category term="web artisan"/><category term="web terminal"/><category term="xampp"/><category term="yosemite"/><category term="zipcode"/><title type='text'>PHPer</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>65</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-2001283674912251994</id><published>2016-06-06T01:22:00.003+08:00</published><updated>2016-06-06T10:46:31.363+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="php"/><category scheme="http://www.blogger.com/atom/ns#" term="taiwan"/><category scheme="http://www.blogger.com/atom/ns#" term="twzipcode"/><category scheme="http://www.blogger.com/atom/ns#" term="zipcode"/><title type='text'>php版 取得台灣地址區碼</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
常常為了地址的事情感到麻煩，所以寫了一個程式能把舊5都地址轉新5都地址，再取得區碼的程式

[packagist.org](https://packagist.org/packages/recca0120/twzipcode)
[github](https://github.com/recca0120/twzipcode)

```bash
composer require recca0120/twzipcode
```

```php
use Recca0120\Twzipcode\Twzipcode;


$twzipcode = new Twzipcode(&#39;北 縣　萬里鄉中正路100號&#39;);
$twzipcode-&gt;getZipcode(); // 207
$twzipcode-&gt;getCounty(); // 新北市
$twzipcode-&gt;getDistrict(); // 萬里區
$twzipcode-&gt;getAddress(); // 新北市萬里區中正路100號
$twzipcode-&gt;getShortAddress(); // 中正路100號
```

&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/2001283674912251994/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2016/06/php.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/2001283674912251994'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/2001283674912251994'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2016/06/php.html' title='php版 取得台灣地址區碼'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-1697881979455020444</id><published>2016-06-05T14:55:00.000+08:00</published><updated>2016-06-05T15:15:05.392+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="laravel"/><category scheme="http://www.blogger.com/atom/ns#" term="repository"/><title type='text'>Laravel Repository</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
最近寫好的repository的package
還沒時間整理readme
所以就先拿phpunit來充當readme

[packagist.org](https://packagist.org/packages/recca0120/repository)
[github](https://github.com/recca0120/laravel-repository)

# Laravel Repository

[![Latest Stable Version](https://poser.pugx.org/recca0120/repository/v/stable)](https://packagist.org/packages/recca0120/repository)
[![Total Downloads](https://poser.pugx.org/recca0120/repository/downloads)](https://packagist.org/packages/recca0120/repository)
[![Latest Unstable Version](https://poser.pugx.org/recca0120/repository/v/unstable)](https://packagist.org/packages/recca0120/repository)
[![License](https://poser.pugx.org/recca0120/repository/license)](https://packagist.org/packages/recca0120/repository)
[![Monthly Downloads](https://poser.pugx.org/recca0120/repository/d/monthly)](https://packagist.org/packages/recca0120/repository)
[![Daily Downloads](https://poser.pugx.org/recca0120/repository/d/daily)](https://packagist.org/packages/recca0120/repository)


### Demo in tests/RepositoryTest.php

```php
use Faker\Factory as FakerFactory;
use Illuminate\Database\Eloquent\Model;
use Mockery as m;
use Recca0120\Repository\Criteria;
use Recca0120\Repository\EloquentRepository;

class EloquentRepositoryTest extends PHPUnit_Framework_TestCase
{
    use Laravel;

    public function setUp()
    {
        $app = $this-&gt;createApplication();
        $db = $this-&gt;createDatabase();
        Schema::create(&#39;users&#39;, function ($table) {
            $table-&gt;increments(&#39;id&#39;);
            $table-&gt;string(&#39;name&#39;);
            $table-&gt;string(&#39;email&#39;);
            $table-&gt;string(&#39;password&#39;, 60);
            $table-&gt;rememberToken();
            $table-&gt;timestamps();
        });

        Schema::create(&#39;roles&#39;, function ($table) {
            $table-&gt;increments(&#39;id&#39;);
            $table-&gt;string(&#39;name&#39;);
            $table-&gt;string(&#39;description&#39;);
            $table-&gt;timestamps();
        });

        Schema::create(&#39;user_roles&#39;, function ($table) {
            $table-&gt;integer(&#39;user_id&#39;);
            $table-&gt;integer(&#39;role_id&#39;);
        });

        $faker = FakerFactory::create();

        for ($i = 0; $i &lt; 3; $i++) {
            User::create([
                &#39;name&#39;     =&gt; sprintf(&#39;%03d&#39;, $i + 1),
                &#39;email&#39;    =&gt; sprintf(&#39;%03d@test.com&#39;, $i + 1),
                &#39;password&#39; =&gt; $faker-&gt;text,
            ]);
        }

        Role::create([
            &#39;name&#39;        =&gt; &#39;superuser&#39;,
            &#39;description&#39; =&gt; &#39;superuser&#39;,
        ]);

        Role::create([
            &#39;name&#39;        =&gt; &#39;administrator&#39;,
            &#39;description&#39; =&gt; &#39;administrator&#39;,
        ]);

        User::find(1)-&gt;roles()-&gt;sync([1]);
    }

    public function tearDown()
    {
        m::close();
        Schema::drop(&#39;users&#39;);
    }

    public function test_repository_create()
    {
        $repository = new EloquentRepository(new User());
        $repositoryUser = $repository-&gt;create([
            &#39;name&#39;     =&gt; &#39;test9999&#39;,
            &#39;email&#39;    =&gt; &#39;test9999@test.com&#39;,
            &#39;password&#39; =&gt; str_random(30),
        ]);

        $modelUser = User::where(&#39;name&#39;, &#39;=&#39;, &#39;test9999&#39;)-&gt;first();

        $this-&gt;assertSame($repositoryUser-&gt;id, $modelUser-&gt;id);
    }

    public function test_repository_find()
    {
        $repository = new EloquentRepository(new User());
        $repositoryUser = $repository-&gt;find(1);

        $modelUser = User::find(1);

        $this-&gt;assertSame($repositoryUser-&gt;id, $modelUser-&gt;id);
    }

    public function test_repository_update()
    {
        $repository = new EloquentRepository(new User());
        $repositoryUser = $repository-&gt;update([
            &#39;password&#39; =&gt; &#39;test_update&#39;,
        ], 2);

        $modelUser = User::find(2);

        $this-&gt;assertSame($repositoryUser-&gt;id, $modelUser-&gt;id);
        $this-&gt;assertSame($modelUser-&gt;password, &#39;test_update&#39;);
    }

    public function test_repository_delete()
    {
        $counter = User::count();
        $repository = new EloquentRepository(new User());

        $this-&gt;assertTrue($repository-&gt;delete(1));
        $this-&gt;assertSame(User::count(), $counter - 1);
    }

    public function test_repository_find_all()
    {
        $repository = new EloquentRepository(new User());
        $repositoryUsers = $repository-&gt;findAll();
        $modelUsers = User::all();
        $this-&gt;assertSame($repositoryUsers-&gt;toArray(), $modelUsers-&gt;toArray());
    }

    public function test_find_by_criteria()
    {
        $repository = new EloquentRepository(new User());
        $criteria = (new Criteria())
            -&gt;where(&#39;name&#39;, &#39;0001&#39;)
            -&gt;having(&#39;email&#39;, &#39;=&#39;, &#39;0001@test.com&#39;)
            -&gt;groupBy(&#39;name&#39;);
        $repositoryUsers = $repository-&gt;findBy($criteria);

        $modelUsers = User::where(&#39;name&#39;, &#39;like&#39;, &#39;0001&#39;)
            -&gt;where(&#39;email&#39;, &#39;0001@test.com&#39;)
            -&gt;groupBy(&#39;name&#39;)
            -&gt;get();

        $this-&gt;assertSame($repositoryUsers-&gt;toArray(), $modelUsers-&gt;toArray());
    }

    public function test_find_by_criteria_where()
    {
        $repository = new EloquentRepository(new User());
        $criteria = (new Criteria())
            -&gt;where(&#39;name&#39;, &#39;0001&#39;);
        $repositoryUsers = $repository-&gt;findBy($criteria);

        $modelUsers = User::where(&#39;name&#39;, &#39;0001&#39;)
            -&gt;get();

        $this-&gt;assertSame($repositoryUsers-&gt;toArray(), $modelUsers-&gt;toArray());
    }

    public function test_find_by_criteria_where_closure()
    {
        $repository = new EloquentRepository(new User());
        $criteria = (new Criteria())
            -&gt;where(function ($criteria) {
                return $criteria-&gt;where(&#39;name&#39;, &#39;0001&#39;);
            });
        $repositoryUsers = $repository-&gt;findBy($criteria);

        $modelUsers = User::where(function ($query) {
                return $query-&gt;where(&#39;name&#39;, &#39;0001&#39;);
            })-&gt;get();

        $this-&gt;assertSame($repositoryUsers-&gt;toArray(), $modelUsers-&gt;toArray());
    }

    public function test_find_by_criteria_or_where()
    {
        $repository = new EloquentRepository(new User());
        $criteria = (new Criteria())
            -&gt;where(&#39;name&#39;, &#39;0001&#39;)
            -&gt;orWhere(&#39;name&#39;, &#39;0002&#39;);
        $repositoryUsers = $repository-&gt;findBy($criteria);

        $modelUsers = User::where(&#39;name&#39;, &#39;0001&#39;)
            -&gt;orWhere(&#39;name&#39;, &#39;0002&#39;)
            -&gt;get();

        $this-&gt;assertSame($repositoryUsers-&gt;toArray(), $modelUsers-&gt;toArray());
    }

    public function test_find_by_criteria_or_where_closure()
    {
        $repository = new EloquentRepository(new User());
        $criteria = (new Criteria())
            -&gt;where(function ($criteria) {
                return $criteria-&gt;where(&#39;name&#39;, &#39;0001&#39;)
                    -&gt;orWhere(&#39;name&#39;, &#39;0002&#39;);
            });
        $repositoryUsers = $repository-&gt;findBy($criteria);

        $modelUsers = User::where(function ($query) {
                return $query-&gt;where(&#39;name&#39;, &#39;0001&#39;)
                    -&gt;orWhere(&#39;name&#39;, &#39;0002&#39;);
            })-&gt;get();

        $this-&gt;assertSame($repositoryUsers-&gt;toArray(), $modelUsers-&gt;toArray());
    }

    public function test_criteria_where_has()
    {
        $repository = new EloquentRepository(new User());
        $criteria = (new Criteria())
            -&gt;whereHas(&#39;roles&#39;, function ($criteria) {
                return $criteria-&gt;where(&#39;id&#39;, &#39;=&#39;, 1);
            });
        $repositoryUsers = $repository-&gt;findBy($criteria);

        $modelUsers = User::whereHas(&#39;roles&#39;, function ($query) {
                return $query-&gt;where(&#39;id&#39;, &#39;=&#39;, 1);
            })
            -&gt;get();

        $this-&gt;assertSame($repositoryUsers-&gt;toArray(), $modelUsers-&gt;toArray());
    }

    public function test_criteria_join()
    {
        $repository = new EloquentRepository(new User());
        $criteria = (new Criteria())
            -&gt;join(&#39;user_roles&#39;, function ($criteria) {
                return $criteria-&gt;on(&#39;users.id&#39;, &#39;=&#39;, &#39;user_roles.user_id&#39;);
            });
        $repositoryUsers = $repository-&gt;findBy($criteria);

        $modelUsers = User::join(&#39;user_roles&#39;, function ($query) {
                return $query-&gt;on(&#39;users.id&#39;, &#39;=&#39;, &#39;user_roles.user_id&#39;);
            })
            -&gt;get();

        $this-&gt;assertSame($repositoryUsers-&gt;toArray(), $modelUsers-&gt;toArray());
    }

    public function test_criteria_order_by()
    {
        $repository = new EloquentRepository(new User());
        $criteria = (new Criteria())
            -&gt;orderBy(&#39;name&#39;, &#39;desc&#39;);
        $repositoryUsers = $repository-&gt;findBy($criteria);

        $modelUsers = User::orderBy(&#39;name&#39;, &#39;desc&#39;)
            -&gt;get();

        $this-&gt;assertSame($repositoryUsers-&gt;toArray(), $modelUsers-&gt;toArray());
    }

    public function test_criteria_select()
    {
        $repository = new EloquentRepository(new User());
        $criteria = (new Criteria())
            -&gt;select(&#39;name&#39;);
        $repositoryUsers = $repository-&gt;findBy($criteria);

        $modelUsers = User::select(&#39;name&#39;)
            -&gt;get();

        $this-&gt;assertSame($repositoryUsers-&gt;toArray(), $modelUsers-&gt;toArray());
    }

    public function test_criteria_experssion()
    {
        $repository = new EloquentRepository(new User());
        $criteria = (new Criteria())
            -&gt;select(Criteria::expr(&#39;REPLACE(name, &quot;0001&quot;, &quot;0003&quot;)&#39;));
        $repositoryUsers = $repository-&gt;findBy($criteria);

        $modelUsers = User::select(DB::raw(&#39;REPLACE(name, &quot;0001&quot;, &quot;0003&quot;)&#39;))
            -&gt;get();

        $this-&gt;assertSame($repositoryUsers-&gt;toArray(), $modelUsers-&gt;toArray());
    }

    public function test_criteria_paginated()
    {
        $repository = new EloquentRepository(new User());
        $repositoryUsers = $repository-&gt;paginatedAll(15);

        $modelUsers = User::paginate(15);

        $this-&gt;assertSame($repositoryUsers-&gt;toArray(), $modelUsers-&gt;toArray());
    }

    public function test_criteria_with()
    {
        $repository = new EloquentRepository(new User());
        $criteria = (new Criteria())
            -&gt;with(&#39;roles&#39;);
        $repositoryUsers = $repository-&gt;findBy($criteria);

        $modelUsers = User::with(&#39;roles&#39;)-&gt;get();

        $this-&gt;assertSame($repositoryUsers-&gt;toArray(), $modelUsers-&gt;toArray());
    }

    public function test_find_by_array()
    {
        $repository = new EloquentRepository(new User());
        $repositoryUsers = $repository-&gt;findBy([
            [&#39;name&#39;, &#39;=&#39;, &#39;0002&#39;],
            [&#39;email&#39;, &#39;=&#39;, &#39;0002@test.com&#39;],
        ]);

        $modelUsers = User::where(&#39;name&#39;, &#39;0002&#39;)
            -&gt;where(&#39;email&#39;, &#39;0002@test.com&#39;)-&gt;get();

        $this-&gt;assertSame($repositoryUsers-&gt;toArray(), $modelUsers-&gt;toArray());
    }

    public function test_find_by_array_key()
    {
        $repository = new EloquentRepository(new User());
        $repositoryUsers = $repository-&gt;findBy([
                &#39;name&#39;  =&gt; &#39;0002&#39;,
                &#39;email&#39; =&gt; &#39;0002@test.com&#39;,
            ]);

        $modelUsers = User::where(&#39;name&#39;, &#39;0002&#39;)
            -&gt;where(&#39;email&#39;, &#39;0002@test.com&#39;)-&gt;get();

        $this-&gt;assertSame($repositoryUsers-&gt;toArray(), $modelUsers-&gt;toArray());
    }

    public function test_custom_criteria()
    {
        $repository = new EloquentRepository(new User());
        $repositoryUsers = $repository-&gt;findBy(new CustomCriteria());

        $modelUsers = User::where(&#39;name&#39;, &#39;0002&#39;)-&gt;get();

        $this-&gt;assertSame($repositoryUsers-&gt;toArray(), $modelUsers-&gt;toArray());
    }

    public function test_multiple_criteria()
    {
        $repository = new EloquentRepository(new User());
        $repositoryUsers = $repository-&gt;findBy([
            new CustomCriteria(),
            (new Criteria())-&gt;orderBy(&#39;name&#39;, &#39;desc&#39;),
        ]);

        $modelUsers = User::where(&#39;name&#39;, &#39;0002&#39;)
            -&gt;orderBy(&#39;name&#39;, &#39;desc&#39;)-&gt;get();

        $this-&gt;assertSame($repositoryUsers-&gt;toArray(), $modelUsers-&gt;toArray());
    }
}

class CustomCriteria extends Criteria
{
    public function __construct()
    {
        $this-&gt;where(&#39;name&#39;, &#39;0002&#39;);
    }
}

class User extends Model
{
    protected $fillable = [
        &#39;name&#39;, &#39;email&#39;, &#39;password&#39;,
    ];

    public function roles()
    {
        return $this-&gt;belongsToMany(
            Role::class,
            &#39;user_roles&#39;,
            &#39;role_id&#39;,
            &#39;user_id&#39;
        );
    }
}

class Role extends Model
{
    protected $fillable = [
        &#39;name&#39;, &#39;description&#39;,
    ];

    public function users()
    {
        return $this-&gt;belongsToMany(
            self::class,
            &#39;user_roles&#39;,
            &#39;user_id&#39;,
            &#39;role_id&#39;
        );
    }
}

function dump()
{
    call_user_func_array(&#39;var_dump&#39;, func_get_args());
}
```
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/1697881979455020444/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2016/06/laravel-repository.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/1697881979455020444'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/1697881979455020444'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2016/06/laravel-repository.html' title='Laravel Repository'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-7867376187735808565</id><published>2016-06-05T14:53:00.001+08:00</published><updated>2016-06-05T15:14:09.702+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="artisan"/><category scheme="http://www.blogger.com/atom/ns#" term="laravel"/><category scheme="http://www.blogger.com/atom/ns#" term="terminal"/><category scheme="http://www.blogger.com/atom/ns#" term="web artisan"/><category scheme="http://www.blogger.com/atom/ns#" term="web terminal"/><title type='text'>Laravel Terminal</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
這是一個將artisan移植到web介面的package，
並增加了一些自定義的command
在server不支援bash shell時，還能執行一些aritsan的命令

[packagist.org](https://packagist.org/packages/recca0120/terminal)
[github](https://github.com/recca0120/laravel-terminal)

# Laravel Web Artisan

[![Latest Stable Version](https://poser.pugx.org/recca0120/terminal/v/stable)](https://packagist.org/packages/recca0120/terminal)
[![Total Downloads](https://poser.pugx.org/recca0120/terminal/downloads)](https://packagist.org/packages/recca0120/terminal)
[![Latest Unstable Version](https://poser.pugx.org/recca0120/terminal/v/unstable)](https://packagist.org/packages/recca0120/terminal)
[![License](https://poser.pugx.org/recca0120/terminal/license)](https://packagist.org/packages/recca0120/terminal)
[![Monthly Downloads](https://poser.pugx.org/recca0120/terminal/d/monthly)](https://packagist.org/packages/recca0120/terminal)
[![Daily Downloads](https://poser.pugx.org/recca0120/terminal/d/daily)](https://packagist.org/packages/recca0120/terminal)

## Installation

Add Presenter to your composer.json file:

```js
&quot;require&quot;: {
    &quot;recca0120/terminal&quot;: &quot;^1.3.3&quot;
}
```
Now, run a composer update on the command line from the root of your project:

```
composer update
```

### Registering the Package

Include the service provider within `app/config/app.php`. The service povider is needed for the generator artisan command.

```php
&#39;providers&#39; =&gt; [
    ...
    Recca0120\Terminal\ServiceProvider::class,
    ...
];
```

publish

```php
artisan vendor:publish --provider=&quot;Recca0120\Terminal\ServiceProvider&quot;
```


### URL

http://localhost/path/to/terminal

### Whitelist
```php
return [
    &#39;whitelists&#39; =&gt; [&#39;127.0.0.1&#39;, &#39;your ip&#39;],
];

```

## Available Commands

*   artisan
*   artisan tinker
*   find
*   mysql

### Find

not full support, but you can delete file use this function (please check file permission)

```bash
find ./vendor -name tests -type d -maxdepth 4 -delete
```

## Add Your Command

### Add Command Class
```php
// src/Console/Commands/Mysql.php

namespace Recca0120\Terminal\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;

class Inspire extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = &#39;inspire&#39;;

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = &#39;Display an inspiring quote&#39;;

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $this-&gt;comment(PHP_EOL.Inspiring::quote().PHP_EOL);
    }
}
```

### Add Command
```php
// src/Console/Kernel.php
namespace Recca0120\Terminal\Console;

use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Recca0120\Terminal\Console\Application as Artisan;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        Commands\Inspire::class,
    ];
}

```
## ScreenShot

### Available Commands
```bash
$ help
```
![Available Commands](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/available-commands.png)

### Artisan List
```bash
$ artisan
```
![Artisan List](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/artisan-list.png)

### Migrate
```bash
$ artisan migrate --seed
```
![Migrate](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/artisan-migrate.png)

### Artisan Tinker
```bash
$ artisan tinker
```
![Tinker](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/artisan-tinker.png)

### Find Command
```bash
$ find ./ -name * -maxdepth 1
```
![Find Command](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/find-command.png)

### Find and Delete
```bash
$ find ./storage/logs -name * -maxdepth 1 -delete
```
![Find and Delete](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/find-and-delete.png)

### Vi
```bash
$ vi server.php
```
![Vi Command](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/vi-command.png)

![Vi Editor](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/vi-editor.png)

![Vi Save](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/vi-save.png)

### Tail
```bash
$ tail
$ tail --line=1
$ tail server.php
$ tail server.php --line 5
```
![Tail Command](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/tail-command.png)


### Cleanup
```bash
$ cleanup
```
![Cleanup Command](https://cdn.rawgit.com/recca0120/terminal/master/screenshots/cleanup-command.png)
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/7867376187735808565/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2016/06/commentphpeol.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/7867376187735808565'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/7867376187735808565'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2016/06/commentphpeol.html' title='Laravel Terminal'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-6775689828270645471</id><published>2016-06-05T14:52:00.000+08:00</published><updated>2016-06-05T15:13:09.024+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="debug"/><category scheme="http://www.blogger.com/atom/ns#" term="laravel"/><category scheme="http://www.blogger.com/atom/ns#" term="tracy"/><title type='text'>Laravel Tracy</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
一個laravel的debug工具，它是MIT的！大家可以安裝來試看看
用得習慣的話就請多多使用....

[packagist.org](https://packagist.org/packages/recca0120/laravel-tracy)
[github](https://github.com/recca0120/laravel-tracy)

## [Nette Tracy](https://github.com/nette/tracy.git) for Laravel 5

Better Laravel Exception Handler

[![Latest Stable Version](https://poser.pugx.org/recca0120/laravel-tracy/v/stable)](https://packagist.org/packages/recca0120/laravel-tracy)
[![Total Downloads](https://poser.pugx.org/recca0120/laravel-tracy/downloads)](https://packagist.org/packages/recca0120/laravel-tracy)
[![Latest Unstable Version](https://poser.pugx.org/recca0120/laravel-tracy/v/unstable)](https://packagist.org/packages/recca0120/laravel-tracy)
[![License](https://poser.pugx.org/recca0120/laravel-tracy/license)](https://packagist.org/packages/recca0120/laravel-tracy)
[![Monthly Downloads](https://poser.pugx.org/recca0120/laravel-tracy/d/monthly)](https://packagist.org/packages/recca0120/laravel-tracy)
[![Daily Downloads](https://poser.pugx.org/recca0120/laravel-tracy/d/daily)](https://packagist.org/packages/recca0120/laravel-tracy)

&lt;img src=&quot;https://cdn.rawgit.com/recca0120/laravel-tracy/master/screenshots/tracy.png&quot; width=&quot;100%&quot; /&gt;

## Features
- Visualization of errors and exceptions
- Debugger Bar
- Exception stack trace contains values of all method arguments.

## Online Demo
[Demo](https://cdn.rawgit.com/recca0120/laravel-tracy/master/screenshots/tracy-exception.html)

## Installing

To get the latest version of Laravel Exceptions, simply require the project using [Composer](https://getcomposer.org):

```bash
composer require recca0120/laravel-tracy
```

Instead, you may of course manually update your require block and run `composer update` if you so choose:

```json
{
    &quot;require&quot;: {
        &quot;recca0120/laravel-tracy&quot;: &quot;~1.3.5&quot;
    }
}
```

Include the service provider within `config/app.php`. The service povider is needed for the generator artisan command.

```php
&#39;providers&#39; =&gt; [
    ...
    Recca0120\LaravelTracy\ServiceProvider::class,
    ...
];
```

publish

```bash
artisan vendor:publish --provider=&quot;Recca0120\LaravelTracy\ServiceProvider&quot;
```
## Config
```php
return [
    &#39;ajax&#39;      =&gt; [
        &#39;debugbar&#39;           =&gt; false, // enable render debugbar when http request is ajax
        &#39;gzCompressLevel&#39;    =&gt; 5,    // gzcompress level
        /*
        * http://stackoverflow.com/questions/3326210/can-http-headers-be-too-big-for-browsers/3431476#3431476
        * Lowest limit found in popular browsers:
        *   - 10KB per header
        *   - 256 KB for all headers in one response.
        *   - Test results from MacBook running Mac OS X 10.6.4:
        */
        &#39;maxHeaderSize&#39;   =&gt; 102400, // 102400b its =&gt; 100 kb
    ],
    &#39;basePath&#39;     =&gt; null,
    &#39;strictMode&#39;   =&gt; true,
    &#39;maxDepth&#39;     =&gt; 4,
    &#39;maxLen&#39;       =&gt; 1000,
    &#39;showLocation&#39; =&gt; true,
    &#39;editor&#39;       =&gt; &#39;subl://open?url=file://%file&amp;line=%line&#39;,
    &#39;panels&#39;       =&gt; [
        &#39;routing&#39;  =&gt; true,
        &#39;database&#39; =&gt; true,
        &#39;view&#39;     =&gt; true,
        &#39;session&#39;  =&gt; true,
        &#39;request&#39;  =&gt; true,
        &#39;event&#39;    =&gt; false,
        &#39;user&#39;     =&gt; true,
        &#39;terminal&#39; =&gt; true,
    ],
    // value: js or tracy
    &#39;panelDumpMethod&#39; =&gt; &#39;js&#39;, // tracy dump need more memory
];
```

### Editor Link

windows
```
copy &lt;vendor path&gt;/recca0120/laravel-tracy/tools/subl-handler/subl-handler.vbs to any directory where you want to place

double click subl-handler.vbs and select editor (support eclipse, sublime, notepad++, else...)
```

OSX
```
https://github.com/dhoulb/subl
```

## Debugger Bar

### SystemInfo
![SystemInfo](https://cdn.rawgit.com/recca0120/laravel-tracy/master/screenshots/systeminfo.png)

### Route
![Route](https://cdn.rawgit.com/recca0120/laravel-tracy/master/screenshots/route.png)

### View
![View](https://cdn.rawgit.com/recca0120/laravel-tracy/master/screenshots/view.png)

### Session
![Session](https://cdn.rawgit.com/recca0120/laravel-tracy/master/screenshots/session.png)

### Request
![Request](https://cdn.rawgit.com/recca0120/laravel-tracy/master/screenshots/request.png)

### Login
![Login](https://cdn.rawgit.com/recca0120/laravel-tracy/master/screenshots/login.png)

### Web Artisan
web artisan is another package [recca0120/terminal](https://github.com/recca0120/laravel-terminal)
![Terminal](https://cdn.rawgit.com/recca0120/laravel-tracy/master/screenshots/terminal.png)

#### notice
if you install terminal before, this panel will throw errors, please remove folder `app/resources/views/vendor/terminal`

## ISSUE
when ajax debugbar is enabled and debugbar is bigger than 256k, will throw 500 exception, or browser will be no response

so I try to compress debugbar in php, and decompress debugbar in javascript.

It looks like working at chrome 48.0.2564.116 64bit, windows 10

but if you use Laravel-Tracy and it doesn&#39;t work correctly

you can try
- disable panel [view , request, event]
- panelDumpMethod change to js
- disable ajax debugbar
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/6775689828270645471/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2016/06/laravel-tracy.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/6775689828270645471'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/6775689828270645471'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2016/06/laravel-tracy.html' title='Laravel Tracy'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-2734314043943905920</id><published>2016-05-12T15:13:00.002+08:00</published><updated>2016-05-12T17:23:54.009+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="async"/><category scheme="http://www.blogger.com/atom/ns#" term="co"/><category scheme="http://www.blogger.com/atom/ns#" term="es6"/><category scheme="http://www.blogger.com/atom/ns#" term="generator"/><title type='text'>活用 es6 generator + co 讓async看起來像sync</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
仔細研究了es6的generator function + [co](https://github.com/tj/co &quot;co&quot;)
才發現可以利用它來改善我們的程式寫法
讓程式的可讀性更高

先讓我們看看用Promise來撰寫非同步code的樣子
```javascript
let num = function (num) {
  return new Promise((resolve, reject) =&gt; {
    setTimeout(() =&gt; {
      resolve(num+1);
    }, 500);
  });
}

num(1).then((res) =&gt; {
  return num(res);
}).then((res) =&gt; {
  return num(res);
}).then((res) =&gt; {
  // output
  // promise result: 4
  console.log(`promise result: ${res}`);
});

```

接下來讓我們來看看generator function + [co](https://github.com/tj/co &quot;co&quot;)的寫法
```javascript
let num = function (num) {
  return (callback) =&gt; {
    setTimeout(function() {
      callback(null, num+1);
    }, 500);
  }
}

co(function*() {
  let num1 = yield num(1);
  let num2 = yield num(num1);
  let num3 = yield num(num2);

  return num3;
}).then((res) =&gt; {
  // output
  // generator result: 4
  console.log(`generator result: ${res}`);
});
```

[jsfiddle](https://jsfiddle.net/recca0120/eocp5h2c/ &quot;jsfiddle範例&quot;)
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/2734314043943905920/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2016/05/es6-generator-co-asyncsync.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/2734314043943905920'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/2734314043943905920'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2016/05/es6-generator-co-asyncsync.html' title='活用 es6 generator + co 讓async看起來像sync'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-5801037272962572338</id><published>2016-04-25T04:18:00.000+08:00</published><updated>2016-04-25T04:18:54.049+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="atom"/><category scheme="http://www.blogger.com/atom/ns#" term="editor"/><category scheme="http://www.blogger.com/atom/ns#" term="ubuntu"/><title type='text'>ubuntu下安裝atom editor</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
只要執行三行指令即可
```bash
sudo add-apt-repository ppa:webupd8team/atom
sudo apt-get update
sudo apt-get install atom 
```
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/5801037272962572338/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2016/04/ubuntuatom-editor.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/5801037272962572338'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/5801037272962572338'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2016/04/ubuntuatom-editor.html' title='ubuntu下安裝atom editor'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-3666707778299597761</id><published>2016-04-25T01:48:00.000+08:00</published><updated>2016-04-25T09:20:33.964+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="freetds"/><category scheme="http://www.blogger.com/atom/ns#" term="linux"/><category scheme="http://www.blogger.com/atom/ns#" term="mssql"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><category scheme="http://www.blogger.com/atom/ns#" term="utf8"/><title type='text'>Linux使用php7連接mssql，並設定utf-8</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
使用php7要連接mssql要安裝的套件為pdo_dblib

```bash
# centos
yum install php70w-pdo_dblib.x86_64

# ubuntu
sudo apt-get install freetds-bin php-sybase
```

接下來我們更改freetds的設定檔，裝連線設定為utf8

```bash
# centos
vi /etc/freetds.conf

# ubuntu
sudo vi /etc/freetds/freetds.conf
```

加入兩行設定即可
```ini
# centos
tds version = 7.2
client charset = UTF-8

# ubuntu
tds version = 7.1
client charset = UTF-8
```
![freetds config](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfZxvhvTwGAuP2pwtB80Bbypwb54mp8uAIPe5kAPEB8Swk4l5BFpt0ZncIr_SMZ43RW5ibnF7SOP_AeE5D7PX5JFbk2uBPZkK_Q0jL0MFFlMXRkmgJeUNFv17CszpfALpdfu-HJ23aKN92/s1600/Image+3.png)


設定完成後連線到mssql charset就會是utf8
如果還是顯示為亂碼的話則可以利用tsql的指令來debug

```bash
tsql -S [ip] -U [username] -P [password]
```
![tsql](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhplyPJmyyXaqfmXpo1D9Tl72GhIOrn_P2QgjwASD3-QNn_3YUyVBsCX6FPv0TdYC6D9hhYd2JIVR8OEHZXnBErLy2004Kmsah5y1YOqCoZ5WtiPL5sbYzWiB-6dxaPz3OKny6Ji2qJw-Vf/s1600/Image+2.png)

&lt;/div&gt;

&lt;!--
補充說明：
要能支援utf8有幾個必要條件
- 必須為mssql 2008以上
- 欄位必須指定為nchar或nvarchar
[參考http://stackoverflow.com/questions/12512687/sql-server-utf8-howto](http://stackoverflow.com/questions/12512687/sql-server-utf8-howto)
SET ANSI_NULLS ON;
SET ANSI_WARNINGS ON;
GO
--&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/3666707778299597761/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2016/04/centosphp7mssqlutf-8.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/3666707778299597761'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/3666707778299597761'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2016/04/centosphp7mssqlutf-8.html' title='Linux使用php7連接mssql，並設定utf-8'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-5107931843863858587</id><published>2016-04-03T19:55:00.000+08:00</published><updated>2016-04-03T19:55:00.970+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="defineProperty"/><category scheme="http://www.blogger.com/atom/ns#" term="es6"/><category scheme="http://www.blogger.com/atom/ns#" term="extends"/><category scheme="http://www.blogger.com/atom/ns#" term="prototype"/><title type='text'>es6如何拓增prototype</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
寫es6時要增加Object的prototype
已經和以往的寫法大為不同了
所以就來介紹一下方法吧

```js
// $.inArray 模擬 Array.includes

import $ from &#39;jquery&#39;;

if (!Array.prototype.includes) {
    Object.defineProperty(Array.prototype, &#39;includes&#39;, {
        value(...args) {
            return $.inArray(...args, this) !== -1;
        }
    });
}
```

&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/5107931843863858587/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2016/04/es6prototype.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/5107931843863858587'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/5107931843863858587'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2016/04/es6prototype.html' title='es6如何拓增prototype'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-4977848438714260214</id><published>2016-04-03T19:50:00.002+08:00</published><updated>2016-04-03T19:55:45.554+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="es6"/><category scheme="http://www.blogger.com/atom/ns#" term="jquery"/><category scheme="http://www.blogger.com/atom/ns#" term="promise"/><title type='text'>利用jQuery Promise模擬Native Promise</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
我們在寫es6時，會用到一些es6才有的函式或物件
但如果可以使用jQuery的一些內建函式來模擬的話
我們就不需要import &#39;babel-polyfill&#39;
這樣產出來的javascript檔案就會少個90k左右

以下為程式碼
```js
&#39;use strict&#39;;

import $ from &#39;jquery&#39;;

if (!window.Promise) {
    class Promise {
        constructor(callback) {
            this.deferred = $.Deferred();
            callback((o) =&gt; {
                this.deferred.resolve(o);
            }, (o) =&gt; {
                this.deferred.reject(o);
            });
            this.promise = this.deferred.promise();
        }

        then(resolve, reject) {
            this.promise.done(resolve);
            this.promise.fail(reject);
            return this;
        }

        catch(reject) {
            this.promise.fail(reject);
            return this;
        }
    }

    window.Promise = Promise;
}
```
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/4977848438714260214/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2016/04/jquery-promisenative-promise.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/4977848438714260214'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/4977848438714260214'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2016/04/jquery-promisenative-promise.html' title='利用jQuery Promise模擬Native Promise'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-2487180886950696089</id><published>2016-04-03T19:39:00.001+08:00</published><updated>2016-04-03T19:58:32.550+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="babel"/><category scheme="http://www.blogger.com/atom/ns#" term="babel6"/><category scheme="http://www.blogger.com/atom/ns#" term="constructor"/><category scheme="http://www.blogger.com/atom/ns#" term="es6"/><category scheme="http://www.blogger.com/atom/ns#" term="super"/><title type='text'>解決babel6 class extends 在 ie10 以下版本super無法呼叫 parent constructor</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
先直接看程式碼
```js
class A {
    constructor() {
        console.log(&#39;A&#39;);
    }
}

class B extends A {
    constructor() {
        super();
    }
}

new B();
```

這是一個很簡單物件繼承，預期console內輸出 &quot;A&quot;
實際做了測試之後發現在ie11, chrome, firefox都能正常輸出
但在ie9, ie10卻完全失效
後來查了原因後原來Object.getPrototypeOf在es5及es6的功能完全不同
才造成super失效

在github上已經有人提出兩種出解決方案
1.設定babel的plugins
```json
{
  &quot;presets&quot;: [&quot;react&quot;, &quot;es2015&quot;],
  &quot;plugins&quot;: [
    [&quot;transform-es2015-classes&quot;, { &quot;loose&quot;: true }],
    &quot;transform-proto-to-assign&quot;
  ]
}
```

2.修改Object.getPrototypeOf 來自[https://github.com/seznam/IMA.js-babel6-polyfill](https://github.com/seznam/IMA.js-babel6-polyfill &quot;polyfill&quot;)
```js
(function() {
  var testObject = {};
  if (!(Object.setPrototypeOf || testObject.__proto__)) {
      var nativeGetPrototypeOf = Object.getPrototypeOf;

      Object.getPrototypeOf = function(object) {
          if (object.__proto__) {
              return object.__proto__;
          } else {
              return nativeGetPrototypeOf.call(Object, object);
          }
      }
  }
})();
```



&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/2487180886950696089/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2016/04/babel6-class-extends-ie10.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/2487180886950696089'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/2487180886950696089'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2016/04/babel6-class-extends-ie10.html' title='解決babel6 class extends 在 ie10 以下版本super無法呼叫 parent constructor'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-1231858579855602405</id><published>2016-03-13T21:46:00.003+08:00</published><updated>2016-03-13T21:52:24.429+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="__call"/><category scheme="http://www.blogger.com/atom/ns#" term="composite"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><title type='text'>php composite + __call</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
```php
class Weapon
{
    protected $name;

    protected $attack = 0;

    protected $addions = [];

    public function __construct($name, $attack, $addions = [])
    {
        $this-&gt;name = $name;
        $this-&gt;attack = $attack;
        $this-&gt;addions = $addions;
    }

    public function setAttack($attack)
    {
        $this-&gt;attack = $attack;
    }

    public function attack()
    {
        $attack = $this-&gt;attack;
        foreach ($this-&gt;addions as $addion) {
            $attack += $addion-&gt;attack();
        }

        return $attack;
    }

    public function __call($method, $parameters)
    {
        foreach ($this-&gt;addions as $addion) {
            if (method_exists($addion, $method) === true) {
                return call_user_func_array([$addion, $method], $parameters);
            }
        }
        die(&#39;error&#39;);
    }
}

abstract class Addion
{
    protected $attack = 0;

    public function attack()
    {
        return $this-&gt;attack;
    }
}

class ToxicAddion extends Addion
{
    protected $attack = 15;

    public function toxic()
    {
        echo &#39;toxic&#39;;
    }
}

class LightingAddion extends Addion
{
    protected $attack = 10;

    public function lighting()
    {
        echo &#39;lighting&#39;;
    }
}

$sword = new Weapon(&#39;劍&#39;, 10, [
    new ToxicAddion(),
    new LightingAddion(),
]);

echo $sword-&gt;attack();
echo $sword-&gt;toxic();
echo $sword-&gt;lighting();

// output
// 35
// toxic
// lighting
```
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/1231858579855602405/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2016/03/php-composite-call.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/1231858579855602405'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/1231858579855602405'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2016/03/php-composite-call.html' title='php composite + __call'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-9086888506096251914</id><published>2016-03-13T21:36:00.000+08:00</published><updated>2016-03-13T21:47:57.652+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="__call"/><category scheme="http://www.blogger.com/atom/ns#" term="decorator"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><title type='text'>PHP decorator + __call</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
```
class Weapon
{
    public function attack()
    {
        return 10;
    }
}

abstract class Decorator
{
    protected $weapon;

    public function __construct($weapon)
    {
        $this-&gt;weapon = $weapon;
    }

    abstract public function attack();

    public function __call($method, $parameters)
    {
        return call_user_func_array([$this-&gt;weapon, $method], $parameters);
    }
}

class ToxicDecorator extends Decorator
{
    public function attack()
    {
        return $this-&gt;weapon-&gt;attack() + 15;
    }

    public function toxic()
    {
        echo &#39;toxic&#39;;
    }
}

class LightingDecorator extends Decorator
{
    public function attack()
    {
        return $this-&gt;weapon-&gt;attack() + 5;
    }

    public function lighting()
    {
        echo &#39;lighting&#39;;
    }
}

$weapon = new Weapon();
$weapon = new ToxicDecorator($weapon);
$weapon = new LightingDecorator($weapon);
echo $weapon-&gt;attack();
echo $weapon-&gt;toxic();
echo $weapon-&gt;lighting();

// output
// 30
// toxic
// lighting
```
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/9086888506096251914/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2016/03/php-decorator-call.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/9086888506096251914'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/9086888506096251914'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2016/03/php-decorator-call.html' title='PHP decorator + __call'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-9074568042778294846</id><published>2016-02-16T12:42:00.001+08:00</published><updated>2016-02-16T12:45:45.539+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="php"/><category scheme="http://www.blogger.com/atom/ns#" term="template"/><title type='text'>PHP 超簡易的樣版引擎</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
PHP的樣版引擎實在是多到不可數
而且每個樣版引擎的做法都不盡相同
有時何我們只需要一個很簡單的把php程式碼分離
就可以用這個最簡單的做法

test.php
```php
&amp;lt;?php foreach ($data as $v): ?&amp;gt;
    &amp;lt;?php echo $v; ?&amp;gt;
&amp;lt;?php endforeach; ?&amp;gt;
```

view.php
```php
function view($file, $data)
{
    ob_start();
    extract($data);
    require $file;

    return ob_get_clean();
}

echo view(&#39;test.php&#39;, [&#39;data&#39; =&gt; [
    1, 2, 3,
]]);

```
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/9074568042778294846/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2016/02/php.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/9074568042778294846'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/9074568042778294846'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2016/02/php.html' title='PHP 超簡易的樣版引擎'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-3566744827572516672</id><published>2016-02-16T12:11:00.002+08:00</published><updated>2016-02-16T12:15:06.307+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="blade"/><category scheme="http://www.blogger.com/atom/ns#" term="laravel"/><category scheme="http://www.blogger.com/atom/ns#" term="standalone"/><category scheme="http://www.blogger.com/atom/ns#" term="view"/><title type='text'>獨立使用Laravel Blade Template Engine</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
有別於之前獨立使用Socialite
這次我們利用ServiceProvider來設定Laravel Blade Engine

利用composer安裝 illuminate/view
```
composer require illunimate/view
```

config.php

```php
require __DIR__.&#39;/vendor/autoload.php&#39;;

use Illuminate\Container\Container;
use Illuminate\Events\Dispatcher;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Fluent;
use Illuminate\View\ViewServiceProvider;

$app = new Container();
$app[&#39;events&#39;] = new Dispatcher();
$app[&#39;config&#39;] = new Fluent();
$app[&#39;files&#39;] = new Filesystem();

// 設定view資料夾
$app[&#39;config&#39;][&#39;view.paths&#39;] = [__DIR__.&#39;/views/&#39;];
// 設定快取資料夾
$app[&#39;config&#39;][&#39;view.compiled&#39;] = __DIR__.&#39;/compiled/&#39;;

// 利用ServiceProvider來初始化View
$serviceProvider = new ViewServiceProvider($app);
// 註冊
$serviceProvider-&gt;register();
// boot
$serviceProvider-&gt;boot();

Facade::setFacadeApplication($app);

// 設Facade View Alias方便使用
class_alias(View::class, &#39;View&#39;);

```

views/test.blade.php
```php
@foreach ([1,2,3] as $v)
    {{ $v }}
@endforeach

```

index.php
```php
require __DIR__.&#39;/config.php&#39;;

echo View::make(&#39;test&#39;)-&gt;render();
```

完整檔案在[Github](https://github.com/recca0120/laravel-blade-standalone-demo)

&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/3566744827572516672/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2016/02/laravel-blade-template-engine.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/3566744827572516672'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/3566744827572516672'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2016/02/laravel-blade-template-engine.html' title='獨立使用Laravel Blade Template Engine'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-2626488087237834525</id><published>2016-02-04T01:07:00.003+08:00</published><updated>2016-02-04T01:07:43.247+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="application"/><category scheme="http://www.blogger.com/atom/ns#" term="laravel"/><category scheme="http://www.blogger.com/atom/ns#" term="mock"/><category scheme="http://www.blogger.com/atom/ns#" term="phpunit"/><title type='text'>Mock Laravel Application</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
研究了好久的mockery終於理出一些頭緒了

Laravel的Application的Mock原來如此簡單

```php
m::mock(&#39;Illuminate\Container\Container, Illuminate\Contracts\Foundation\Application&#39;)
    -&gt;makePartial()
    -&gt;shouldReceive(&#39;basePath&#39;)-&gt;andReturn(realpath(__DIR__.&#39;/../&#39;).&#39;/&#39;)
    -&gt;shouldReceive(&#39;version&#39;)-&gt;andReturn(&#39;5.x.testing&#39;)
    -&gt;shouldReceive(&#39;environment&#39;)-&gt;andReturn(&#39;testing&#39;)
    -&gt;mock();
```
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/2626488087237834525/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2016/02/mock-laravel-application.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/2626488087237834525'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/2626488087237834525'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2016/02/mock-laravel-application.html' title='Mock Laravel Application'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-2430358402522840986</id><published>2016-02-01T05:33:00.001+08:00</published><updated>2016-02-01T05:35:45.843+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="laravel"/><category scheme="http://www.blogger.com/atom/ns#" term="socialite"/><category scheme="http://www.blogger.com/atom/ns#" term="standalone"/><title type='text'>獨立使用Laravel Socialite</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
有別於前一篇，這次我們用不使用Illuminate\Container\Container來執行Laravel Socialite

## composer

```
 composer require laravel/socialite
```

## php

```php
require __DIR__.&#39;/vendor/autoload.php&#39;;

use Illuminate\Http\Request;
use Illuminate\Support\Fluent;
use Laravel\Socialite\SocialiteManager;
use Symfony\Component\HttpFoundation\Session\Session;

/*
 * 用   \Illuminate\Support\Fluent
 * 替代 \Illuminate\Container\Container
 */
$app = new Fluent();

/*
 * 用   \Illuminate\Support\Fluent
 * 替代 \Illuminate\Contracts\Config\Repository
 */
$config = new Fluent();

/*
 * 取得 Request
 */
$request = Request::capture();

/*
 * 使用 Symfony Session
 */
$session = new Session();

/*
 * session start
 */
$session-&gt;start();

/*
 * 設置 session
 */
$request-&gt;setSession($session);

/*
 * Facebook飍數
 */
$config[&#39;services.facebook&#39;] = [
    &#39;client_id&#39;     =&gt; &#39;900358040081723&#39;,
    &#39;client_secret&#39; =&gt; &#39;06134ad6946069c6457d06688b22c259&#39;,
    &#39;redirect&#39;      =&gt; &#39;http://localhost/test/socialite/index.php/callback&#39;,
];

/*
 * 將 config, request置入 app
 */
$app[&#39;config&#39;] = $config;
$app[&#39;request&#39;] = $request;

// 以上為 socalite app所需設定，接下來參考官方文件即可

$socialiteManager = new SocialiteManager($app);
$provider = $socialiteManager
    -&gt;with(&#39;facebook&#39;)
    /*
     * 只要是oauth2就必須執行此方法，
     * 因為我們用的是Symfony Session而不是Laravel Session
     */
    -&gt;stateless();

if (strpos($_SERVER[&#39;REQUEST_URI&#39;], &#39;/callback&#39;) === false) {
    $response = $provider-&gt;redirect();

    return $response-&gt;send();
}

var_dump((array) $provider-&gt;user());
```
&lt;/div&gt;

</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/2430358402522840986/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2016/02/laravel-socialite.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/2430358402522840986'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/2430358402522840986'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2016/02/laravel-socialite.html' title='獨立使用Laravel Socialite'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-7946120304532982947</id><published>2016-01-31T02:19:00.002+08:00</published><updated>2016-02-01T03:26:52.201+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="eloquent"/><category scheme="http://www.blogger.com/atom/ns#" term="facade root"/><category scheme="http://www.blogger.com/atom/ns#" term="laravel"/><category scheme="http://www.blogger.com/atom/ns#" term="standalone"/><title type='text'>如何獨立使用Laravel Eloquent</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
Laravel的套件是可以獨立使用的，並不需要加入整個framework
我們一起來了解如何操作


composer 新增套件
```bash
composer require illuminate/container illuminate/contracts illuminate/database illuminate/events illuminate/hashing illuminate/support nesbot/carbon
```

新增bootstrap.php
```php
require __DIR__.&#39;/../vendor/autoload.php&#39;;

use Illuminate\Container\Container;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Str;

class Application extends Container
{
    public $aliases = [
        \Illuminate\Support\Facades\Facade::class  =&gt; &#39;Facade&#39;,
        \Illuminate\Support\Facades\App::class     =&gt; &#39;App&#39;,
        \Illuminate\Support\Facades\Schema::class  =&gt; &#39;Schema&#39;,
    ];

    public function __construct()
    {
        date_default_timezone_set(&#39;UTC&#39;);

        if (class_exists(&#39;\Carbon\Carbon&#39;) === true) {
            \Carbon\Carbon::setTestNow(\Carbon\Carbon::now());
        }

        $this[&#39;app&#39;] = $this;
        $this-&gt;setupAliases();
        $this-&gt;setupDispatcher();
        $this-&gt;setupConnection();
        Facade::setFacadeApplication($this);
        Container::setInstance($this);
    }

    public function setupDispatcher()
    {
        if (class_exists(&#39;\Illuminate\Events\Dispatcher&#39;) === false) {
            return;
        }
        $this[&#39;events&#39;] = new \Illuminate\Events\Dispatcher($this);
    }

    public function setupAliases()
    {
        foreach ($this-&gt;aliases as $className =&gt; $alias) {
            class_alias($className, $alias);
        }
    }

    public function setupConnection()
    {
        if (class_exists(&#39;\Illuminate\Database\Capsule\Manager&#39;) === false) {
            return;
        }

        $connection = new \Illuminate\Database\Capsule\Manager();
        $connection-&gt;addConnection([
            &#39;driver&#39;   =&gt; &#39;sqlite&#39;,
            &#39;database&#39; =&gt; &#39;:memory:&#39;,
        ]);
        if (isset($this[&#39;events&#39;]) === true) {
            $connection-&gt;setEventDispatcher($this[&#39;events&#39;]);
        }
        $connection-&gt;bootEloquent();
        $connection-&gt;setAsGlobal();

        $this[&#39;db&#39;] = $connection;
    }

    public function migrate($method)
    {
        if (class_exists(&#39;\Illuminate\Database\Capsule\Manager&#39;) === false) {
            return;
        }

        foreach (glob(__DIR__.&#39;/../database/migrations/*.php&#39;) as $file) {
            include_once $file;
            if (preg_match(&#39;/\d+_\d+_\d+_\d+_(.*)\.php/&#39;, $file, $m)) {
                $className = Str::studly($m[1]);
                $migration = new $className();
                call_user_func_array([$migration, $method], []);
            }
        }
    }

    public function environment()
    {
        return &#39;testing&#39;;
    }
}

if (function_exists(&#39;bcrypt&#39;) === false) {
    /**
     * Hash the given value.
     *
     * @param string $value
     * @param array  $options
     *
     * @return string
     */
    function bcrypt($value, $options = [])
    {
        return (new \Illuminate\Hashing\BcryptHasher())-&gt;make($value, $options);
    }
}

if (function_exists(&#39;app&#39;) === false) {
    function app()
    {
        return App::getInstance();
    }
}

if (Application::getInstance() == null) {
    new Application();
}
```

只要再建立資料表及建立Model
就可以正常使用Eloquent了


&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/7946120304532982947/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2016/01/laravel-eloquent.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/7946120304532982947'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/7946120304532982947'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2016/01/laravel-eloquent.html' title='如何獨立使用Laravel Eloquent'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-4581222934708385957</id><published>2016-01-03T18:46:00.001+08:00</published><updated>2016-01-03T18:46:49.005+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="git"/><title type='text'>git 刪除遠端branch</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
只要在分支前加入『:』即可

##Example

```bash
git push origin :&lt;branch name&gt;
```
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/4581222934708385957/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2016/01/git-branch.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/4581222934708385957'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/4581222934708385957'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2016/01/git-branch.html' title='git 刪除遠端branch'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-9036715711461523048</id><published>2015-12-28T19:28:00.000+08:00</published><updated>2015-12-28T19:30:04.939+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="escapeshellarg"/><category scheme="http://www.blogger.com/atom/ns#" term="laravel"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><category scheme="http://www.blogger.com/atom/ns#" term="Symfony"/><category scheme="http://www.blogger.com/atom/ns#" term="遠振"/><title type='text'>遠振主機 escapeshellarg() has been disabled for security reasons</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
用遠振主機又踩雷啦，遠振將escapeshellarg這個函式disabled
所以只要有用到
SebastianBergmann\Environment\Runtime
Symfony\Component\Console\Input\Input
Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser
Symfony\Component\Process\ProcessUtils
Tracy\Debugger
都會提示 escapeshellarg() has been disabled for security reasons
不過還好php5.3之後就支援namespace，可以讓我們輕鬆略過這個問題
（如果使用的套件不支援namespace那就只好認命的去修改程式囉）
只要require下面的檔案就可以解決這些問題了

```php
namespace Yuan\Jhen
{
    if (function_exists(&#39;escapeshellarg&#39;) === true) {
        function escapeshellarg($input)
        {
            return \escapeshellarg($input);
        }
    } else {
        function escapeshellarg($input)
        {
            $input = str_replace(&#39;\&#39;&#39;, &#39;\\\&#39;&#39;, $input);

            return &#39;\&#39;&#39;.$input.&#39;\&#39;&#39;;
        }
    }
}

namespace SebastianBergmann\Environment
{
    function escapeshellarg($input)
    {
        return \Yuan\Jhen\escapeshellarg($input);
    }
}

namespace Symfony\Component\Console\Input
{
    function escapeshellarg($input)
    {
        return \Yuan\Jhen\escapeshellarg($input);
    }
}

namespace Symfony\Component\HttpFoundation\File\MimeType
{
    function escapeshellarg($input)
    {
        return \Yuan\Jhen\escapeshellarg($input);
    }
}

namespace Symfony\Component\Process
{
    function escapeshellarg($input)
    {
        return \Yuan\Jhen\escapeshellarg($input);
    }
}

namespace Tracy
{
    function escapeshellarg($input)
    {
        return \Yuan\Jhen\escapeshellarg($input);
    }
}

```
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsakGzmlvmQo2kl-9j7y0GbneNx6kMPj7FUhdOlAS2Y9O0bzGG3GzsKJcZ3bWkVDN-9Z1vjiRVkSneBcl-P-60F7uoqE_R2lCaYHD6gZS2WZn1UgkTVgiQ2iYJV3B3cFt3KdEpQ-wajzXc/s1600/Image+1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsakGzmlvmQo2kl-9j7y0GbneNx6kMPj7FUhdOlAS2Y9O0bzGG3GzsKJcZ3bWkVDN-9Z1vjiRVkSneBcl-P-60F7uoqE_R2lCaYHD6gZS2WZn1UgkTVgiQ2iYJV3B3cFt3KdEpQ-wajzXc/s320/Image+1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/9036715711461523048/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2015/12/escapeshellarg-has-been-disabled-for.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/9036715711461523048'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/9036715711461523048'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2015/12/escapeshellarg-has-been-disabled-for.html' title='遠振主機 escapeshellarg() has been disabled for security reasons'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsakGzmlvmQo2kl-9j7y0GbneNx6kMPj7FUhdOlAS2Y9O0bzGG3GzsKJcZ3bWkVDN-9Z1vjiRVkSneBcl-P-60F7uoqE_R2lCaYHD6gZS2WZn1UgkTVgiQ2iYJV3B3cFt3KdEpQ-wajzXc/s72-c/Image+1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-5602771210304374796</id><published>2015-12-22T04:07:00.001+08:00</published><updated>2015-12-22T04:16:23.203+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="git"/><category scheme="http://www.blogger.com/atom/ns#" term="laravel"/><title type='text'>利用Git來升級Laravel</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
照著影片操作，就會出現conflicts，處理完conflicts之後，再執行

```bash
composer install
```

這樣大致上就升級完畢了，而且如果升級出問題還可以利用git本身的功能來進行還原...
&lt;/div&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe width=&quot;320&quot; height=&quot;266&quot; class=&quot;YOUTUBE-iframe-video&quot; data-thumbnail-src=&quot;https://i.ytimg.com/vi/OtvAwl4Nspk/0.jpg&quot; src=&quot;https://www.youtube.com/embed/OtvAwl4Nspk?feature=player_embedded&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/5602771210304374796/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2015/12/gitlaravel.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/5602771210304374796'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/5602771210304374796'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2015/12/gitlaravel.html' title='利用Git來升級Laravel'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/OtvAwl4Nspk/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-7469442572286169318</id><published>2015-12-20T12:04:00.002+08:00</published><updated>2015-12-20T12:04:27.380+08:00</updated><title type='text'>php 偵測語系</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
```php
function getDefaultLanguage()
{
    if (isset($_SERVER[&#39;HTTP_ACCEPT_LANGUAGE&#39;])) {
        return parseDefaultLanguage($_SERVER[&#39;HTTP_ACCEPT_LANGUAGE&#39;]);
    } else {
        return parseDefaultLanguage(null);
    }
}

function parseDefaultLanguage($http_accept, $deflang = &#39;zh-TW&#39;)
{
    if (isset($http_accept) &amp;&amp; strlen($http_accept) &gt; 1) {
        # Split possible languages into array
        $x = explode(&#39;,&#39;, $http_accept);
        foreach ($x as $val) {
            #check for q-value and create associative array. No q-value means 1 by rule
            if (preg_match(&quot;/(.*);q=([0-1]{0,1}.\d{0,4})/i&quot;, $val, $matches)) {
                $lang[$matches[1]] = (float) $matches[2];
            } else {
                $lang[$val] = 1.0;
            }
        }

        #return default language (highest q-value)
        $qval = 0.0;
        foreach ($lang as $key =&gt; $value) {
            if ($value &gt; $qval) {
                $qval = (float) $value;
                $deflang = $key;
            }
        }
    }

    return strtolower($deflang);
}

echo getDefaultLanguage();
```
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/7469442572286169318/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2015/12/php.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/7469442572286169318'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/7469442572286169318'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2015/12/php.html' title='php 偵測語系'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-9188432784538203839</id><published>2015-12-20T12:02:00.001+08:00</published><updated>2015-12-20T12:03:05.537+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="mysql"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><title type='text'>資料庫備份工具</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
```php
class DatabaseClone
{
    public $link;

    public function __construct($host, $username, $password)
    {
        $this-&gt;link = mysqli_connect($host, $username, $password);
        mysqli_query($this-&gt;link, &#39;SET NAMES utf8&#39;);
        mysqli_query($this-&gt;link, &#39;SET AUTOCOMMIT = 0&#39;);
        mysqli_query($this-&gt;link, &#39;SET UNIQUE_CHECKS = 0&#39;);
        mysqli_query($this-&gt;link, &#39;SET FOREIGN_KEY_CHECKS = 0&#39;);
    }

    public function fetch($query)
    {
        $results = [];
        $query = mysqli_query($this-&gt;link, $query);
        while ($row = mysqli_fetch_assoc($query)) {
            $results[] = $row;
        }

        return $results;
    }

    public function copy($copyTo)
    {
        set_time_limit(-1);
        ini_set(&#39;memory_limit&#39;, -1);
        $query = mysqli_query($this-&gt;link, $sql = &#39;show databases&#39;);
        while ($database = mysqli_fetch_assoc($query)) {
            $database = $database[&#39;Database&#39;];
            if (in_array($database, [&#39;mysql&#39;, &#39;information_schema&#39;, &#39;performance_schema&#39;], true) === true) {
                continue;
            }

            $createDatabase = mysqli_fetch_assoc(mysqli_query($this-&gt;link, &#39;SHOW CREATE DATABASE `&#39;.$database.&#39;`&#39;));
            mysqli_query($copyTo-&gt;link, $sql = &#39;DROP DATABASE IF EXISTS `&#39;.$database.&#39;`&#39;) or var_dump($sql);
            mysqli_query($copyTo-&gt;link, $sql = $createDatabase[&#39;Create Database&#39;]) or var_dump($sql);

            mysqli_select_db($this-&gt;link, $database);
            mysqli_select_db($copyTo-&gt;link, $database);

            $query2 = mysqli_query($this-&gt;link, $sql = &#39;show tables&#39;);
            while ($table = mysqli_fetch_assoc($query2)) {
                $table = current($table);
                $createTable = mysqli_fetch_assoc(mysqli_query($this-&gt;link, &#39;SHOW CREATE TABLE `&#39;.$table.&#39;`&#39;));
                mysqli_query($copyTo-&gt;link, $sql = $createTable[&#39;Create Table&#39;]) or var_dump($sql);
                $counts = current(mysqli_fetch_assoc(mysqli_query($this-&gt;link, &#39;SELECT COUNT(*) as counts FROM `&#39;.$table.&#39;`&#39;)));
                $range = range(0, $counts - 1);
                $offset = 0;
                $limit = 200;
                $chunks = array_chunk($range, $limit);
                foreach ($chunks as $chunk) {
                    $query3 = mysqli_query($this-&gt;link, $sql = &#39;SELECT * FROM `&#39;.$table.&#39;` LIMIT &#39;.$limit.&#39; OFFSET &#39;.$offset) or var_dump($database, $sql);
                    while ($row = mysqli_fetch_assoc($query3)) {
                        $keys = [];
                        $values = [];
                        foreach ($row as $key =&gt; $value) {
                            $keys[] = &#39;`&#39;.$key.&#39;`&#39;;
                            $values[] = &quot;&#39;&quot;.addslashes($value).&quot;&#39;&quot;;
                        }
                        mysqli_query($copyTo-&gt;link, $sql = &#39;INSERT INTO `&#39;.$table.&#39;` (&#39;.implode(&#39;,&#39;, $keys).&#39;) VALUES (&#39;.implode(&#39;,&#39;, $values).&#39;)&#39;) or var_dump($database, $sql);
                    }
                    $offset += count($chunk);
                }
            }
        }
    }
}

$database = new DatabaseClone(&#39;localhost:3306&#39;, &#39;root&#39;, &#39;&#39;);
$database-&gt;copy(new DatabaseClone(&#39;localhost:3308&#39;, &#39;root&#39;, &#39;&#39;));
```
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/9188432784538203839/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2015/12/blog-post.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/9188432784538203839'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/9188432784538203839'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2015/12/blog-post.html' title='資料庫備份工具'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-6100912423859946215</id><published>2015-11-07T05:13:00.002+08:00</published><updated>2015-11-07T05:15:41.680+08:00</updated><title type='text'>使用instance來進行Tracy Panel</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
```php
// PHP程式碼
include __DIR__.&#39;/vendor/autoload.php&#39;;

use Tracy\Debugger;
use Tracy\IBarPanel;

class CustomPanel implements IBarPanel
{
    /**
     * Renders HTML code for custom tab.
     * @return string
     */
    public function getTab()
    {
        return &#39;sql&#39;;
    }

    /**
     * Renders HTML code for custom panel.
     * @return string
     */
    public function getPanel()
    {
        $data = $this-&amp;gt;data;
        ob_start();
        require __DIR__.&#39;/custompanel.php&#39;;

        return ob_get_clean();
    }

    public function push($data)
    {
        $this-&amp;gt;data[] = $data;
    }

    public $data = [];

    private static $_instance;

    public static function instance()
    {
        if (static::$_instance === null) {
            static::$_instance = new static;
        }

        return static::$_instance;
    }
}

// 開發環境
$environment = Debugger::DEVELOPMENT;
// 啟用
Debugger::enable($environment);

Debugger::getBar()
    -&amp;gt;addPanel(CustomPanel::instance());

$i = 0;
CustomPanel::instance()-&amp;gt;push([
    &#39;sql&#39; =&amp;gt; &#39;select * from user where id = &#39;.++$i,
]);

CustomPanel::instance()-&amp;gt;push([
    &#39;sql&#39; =&amp;gt; &#39;select * from user where id = &#39;.++$i,
]);

CustomPanel::instance()-&amp;gt;push([
    &#39;sql&#39; =&amp;gt; &#39;select * from user where id = &#39;.++$i,
]);
```

```php
//樣板&amp;lt;h1&amp;gt;SQL&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&quot;tracy-inner&quot;&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;table&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;?php foreach ($data as $key =&amp;gt; $value): ?&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;&amp;lt;?php echo $value[&#39;sql&#39;]; ?&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;?php endforeach ?&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt; ```
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/6100912423859946215/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2015/11/instancetracy-panel.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/6100912423859946215'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/6100912423859946215'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2015/11/instancetracy-panel.html' title='使用instance來進行Tracy Panel'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-452678882261368194</id><published>2015-10-23T04:03:00.003+08:00</published><updated>2015-10-24T08:30:06.925+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="laravel"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><category scheme="http://www.blogger.com/atom/ns#" term="session"/><title type='text'>Laravel的Session不等於PHP Native Session</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
在Laravel內我們可能寫了以下的程式碼

```php
get(&#39;/session&#39;, function () {
    session_start();
    session()-&gt;put(&#39;foo&#39;, &#39;bar&#39;);
    $_SESSION[&#39;foo&#39;] = &#39;bar&#39;;

    header(&#39;location: &#39;.url(&#39;/session/display&#39;));
    exit;
});

get(&#39;/session/display&#39;, function () {
    session_start();
    ob_start();
    dump(session()-&gt;get(&#39;foo&#39;));
    dump($_SESSION[&#39;foo&#39;]);
    $content = ob_get_clean();

    // output null, &#39;bar&#39;

    return $content;
});
```

會發現輸出結果完全不如我們所預期，為什麼會這樣呢？我們就好好的來做個探討吧...

## 原因出在Laravel的Session根本不是用PHP Native Session

在遇到這個狀況後，於是就去查了一下Laravel Session倒底是怎麼一回事，發現Laravel的程式碼內根本沒有執行session_start()啊

## Laravel Session倒底是怎麼運作的
追了一下Laravel的原始碼，發現它是利用[Illuminate\Session\Middleware\StartSession](https://github.com/illuminate/session/blob/master/Middleware/StartSession.php)來進行php session模擬的，
在Laravel執行的最後階段在將存在記憶體內的資料進行實體寫入，
所以只要在我們只要在程式內任意一個地方執行了php的exit, die, header(&#39;location: xxx&#39;); 
那Session就不會被存入檔案內，自然在下一次連線也就取不到值了

## 有沒有解決方案
有，當然有，只要輸入
```php
get(&#39;/session&#39;, function () {
    session_start();
    session()-&gt;put(&#39;foo&#39;, &#39;bar&#39;);
    $_SESSION[&#39;foo&#39;] = &#39;bar&#39;;
    session()-&gt;save(); // 手動寫入
    dump($_SESSION[&#39;foo&#39;]);
    $content = ob_get_clean();

    // output &#39;bar&#39;, &#39;bar&#39;

    return $content;
});
```
## 後記

為什麼會有這一篇的出現，因為我們可能會用很多其它已經寫好的library，但它們就是有用到session_start();外加header, die, exit等等指令啊，所以記錄一下來提醒自己囉
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/452678882261368194/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2015/10/laravelsessionphp-session.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/452678882261368194'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/452678882261368194'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2015/10/laravelsessionphp-session.html' title='Laravel的Session不等於PHP Native Session'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6534406401424841087.post-4331516682980477567</id><published>2015-09-20T18:12:00.000+08:00</published><updated>2015-10-24T07:20:08.883+08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="laravel"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><category scheme="http://www.blogger.com/atom/ns#" term="socialite"/><title type='text'>重寫Laravel Socialite</title><content type='html'>&lt;div class=&quot;markdown&quot;&gt;
最近需要用到OAuth的Client套件
所以就使用目前最多人使用的Laravel
不過需要的部份只有Laravel Socialite

看了一下composer.json的相依性
```json
    &quot;require&quot;: {
        &quot;php&quot;: &quot;&amp;gt;=5.4.0&quot;,
        &quot;illuminate/contracts&quot;: &quot;~5.0&quot;,
        &quot;illuminate/http&quot;: &quot;~5.0&quot;,
        &quot;illuminate/support&quot;: &quot;~5.0&quot;,
        &quot;guzzlehttp/guzzle&quot;: &quot;~5.0|~6.0&quot;,
        &quot;league/oauth1-client&quot;: &quot;~1.0&quot;
    },
```

只需要這些package並不需要整個Laravel
所以就開始使用它
不過在使用的過程遇到了不少問題
它所需要的package其實不止這些
所以程式在撰寫的過程中確實遇到不少問題
再在上在本機端上開發會遇到cURL error 60: SSL certificate problem
於是決定以[PHPoAuthLib](https://github.com/Lusitanian/PHPoAuthLib.git)進行開發
所以就寫了[Recca0120 Socialite](https://github.com/recca0120/Socialite)
並使它可以獨立使用

[Demo](https://github.com/recca0120/Socialite/tree/master/demo)

目前只先實作Laravel Socialite原本的功能，之後會視情形再加功能

OAuth1
    BitBucket
    Twitter
OAuth2
    Facebook
    GitHub
    Google
    Instagram
    LinkedIn
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://phpwrite.blogspot.com/feeds/4331516682980477567/comments/default' title='張貼留言'/><link rel='replies' type='text/html' href='http://phpwrite.blogspot.com/2015/09/laravel-socialite.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/4331516682980477567'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6534406401424841087/posts/default/4331516682980477567'/><link rel='alternate' type='text/html' href='http://phpwrite.blogspot.com/2015/09/laravel-socialite.html' title='重寫Laravel Socialite'/><author><name>phpwriter</name><uri>http://www.blogger.com/profile/03749787361355769748</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>