Ejemplo n.º 1
0
    Route::post('admin/departments/add', function () {
        $input = Input::get(array('title', 'slug', 'description'));
        $validator = new validator($input);
        $validator->check('title')->is_max(3, __('departments.title_missing'));
        if ($errors = $validator->errors()) {
            Input::flash();
            Notify::error($errors);
            return Response::redirect('admin/departments/add');
        }
        if (empty($input['slug'])) {
            $input['slug'] = $input['title'];
        }
        $input['slug'] = slug($input['slug']);
        $department = department::create($input);
        Extend::process('department', $department->id);
        Notify::success(__('departments.created'));
        return Response::redirect('admin/departments');
    });
    Route::get('admin/departments/delete/(:num)', function ($id) {
        $total = department::count();
        if ($total == 1) {
            Notify::error(__('departments.delete_error'));
            return Response::redirect('admin/departments/edit/' . $id);
        }
        $department = department::where('id', '<>', $id)->fetch();
        department::find($id)->delete();
        Post::where('department', '=', $id)->update(array('department' => $department->id));
        Notify::success(__('departments.deleted'));
        return Response::redirect('admin/departments');
    });
});