PHP code example of five-say / laravel-exception-extend

1. Go to this page and download the library: Download five-say/laravel-exception-extend library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

five-say / laravel-exception-extend example snippets


'aliases' => array(
    ...
    'Validation' => 'FiveSay\ValidationFacade', // 异常化表单验证
),

try {
    Validation::make(array(
        'name' => '..

} catch (FiveSay\ValidationException $e) {
    return Redirect::back()->withErrors($e->errors);
}

Validation::throwIt('name', 'test error message.');

Validation::throwIt(array(
    'name'  => 'test error message.',
    'email' => 'test error message.',
));

    /**
     * 创建
     * @return Response
     */
    public function store()
    {
        try {
            # 表单验证
            Validation::make(array(
                'account'          => 'iles'          => 'multi_mobile',
            ));

            # 创建使用者账号
            $user = User::create(
                array('activated' => true) // 强制激活
                + Input::only('account', 'password', 'name')
            )->setGroupTo('Reception');

            # 创建员工信息
            $staff = Staff::create(
                array(
                    'user_id' => $user->id,
                    'model'   => 'Reception',
                )
                + Input::only('name', 'mobiles')
            );

            # 创建前台
            $reception = Reception::create(
                array(
                    'user_id'  => $user->id,
                    'staff_id' => $staff->id,
                )
                + Input::only('name')
            );

            # 操作成功
            return Redirect::route('home')->withSuccess('操作成功');

        } catch (FiveSay\ValidationException $e) {
            return Redirect::back()->withErrors($e->errors);
        } catch (UserSaveFailException $e) {
            return Redirect::back()->withError('账号信息写入失败');
        } catch (StaffSaveFailException $e) {
            return Redirect::back()->withError('员工信息写入失败');
        } catch (ReceptionSaveFailException $e) {
            return Redirect::back()->withError('前台信息写入失败');
        }
    }

class User extends FiveSay\Model
{ ...

class UserObserver {

    public function saving($model)
    {
        //
    }

    public function saved($model)
    {
        //
    }

}


/*
|--------------------------------------------------------------------------
| 模型观察者
|--------------------------------------------------------------------------
| 模型事件触发顺序
|--------------------------------------------------------------------------
|
| 创建 & 更新
|          |-- creating -- created --|
| saving --|                         |-- saved
|          |-- updating -- updated --|
| 
| 软删除 & 强制删除
|            |-- softing -- softed --|
| deleting --|                       |-- deleted
|            |-- forcing -- forced --|
| 
| 恢复
| restoring -- saving -- updating -- updated -- saved -- restored
| 
*/
class DemoObserver
{
    // ...
}