PHPackages                             mrblackus/laravel-storedprocedures - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. mrblackus/laravel-storedprocedures

ActiveLibrary[Database &amp; ORM](/categories/database)

mrblackus/laravel-storedprocedures
==================================

0.1.2(11y ago)61425[1 issues](https://github.com/mrblackus/laravel-storedprocedures/issues)PHPPHP &gt;=5.4.0

Since Sep 2Pushed 10y ago4 watchersCompare

[ Source](https://github.com/mrblackus/laravel-storedprocedures)[ Packagist](https://packagist.org/packages/mrblackus/laravel-storedprocedures)[ RSS](/packages/mrblackus-laravel-storedprocedures/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (2)Versions (7)Used By (0)

[![Build Status](https://camo.githubusercontent.com/36d7e8d71fcff56503f2cbc8f6804d28f616ca5826e6d8b1df134e2d972394db/68747470733a2f2f7472617669732d63692e6f72672f6d72626c61636b75732f6c61726176656c2d73746f72656470726f636564757265732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mrblackus/laravel-storedprocedures)

Laravel stored procedures
=========================

[](#laravel-stored-procedures)

This package allow you to work with PostgreSQL stored procedures with Laravel 4. It allows you to generate models to simply use your procedures in your PHP code.

**Laravel 5 users**

You can check [this fork](https://github.com/3IE/laravel-storedprocedures) by [3IE](https://github.com/3IE) that made the changes to use laravel-storedprocedures with Laravel 5.

Installation
------------

[](#installation)

### Package installation

[](#package-installation)

#### With Composer

[](#with-composer)

Require this package by adding following dependency on your composer.json

```
"mrblackus/laravel-storedprocedures": "0.1.*"
```

Then update composer with `composer update` or `composer install`.

#### With Laravel bundle

[](#with-laravel-bundle)

If you do not want to use Composer, you can install it by using Laravel Bundle by typing this command

```
php artisan bundle:install StoredProcedure

```

### Registering service provider

[](#registering-service-provider)

Once the package is installed, add the ServiceProvider in `providers` array on app/config/app.php :

```
'providers' => array(
    'Mrblackus\LaravelStoredprocedures\LaravelStoredproceduresServiceProvider'
);
```

Usage
-----

[](#usage)

You can generate model for your stored procedures (aka *functions*) by typing this command

```
php artisan generate-sp

```

**Only stored procedures which name start with `sp_` will have a model generated, other ones will be ignored.**Models will be written in app/store\_procedures directory (or the one defined in configuration file). **Do not edit these models !** They will be overwritten at next generation.

Configuration
-------------

[](#configuration)

You can override default configuration by publishing configuration file and editing it.

```
php artisan config:publish mrblackus/laravel-storedprocedures

```

You can change the database schema to read and the directory where models for stored procedures are written.

```
return array(
    'schema'         => 'public',
    'model_save_dir' => 'stored_procedures/'
);
```

Models
------

[](#models)

Generated models have an `execute()` methods that allow you to execute stored procedure and get result (if the procedure returns one) from it.

If procedure have IN or INOUT parameter, the `execute()` method will have the same parameter in the same order.

If it has OUT or INOUT parameter, model will have an attribute with getter/setter for every OUT parameters.

**Setters will not modify data**, they are only present to allow you to format data if you want to use it on views by uysing whole model instead of simple variables.

Example
-------

[](#example)

Giving the following stored procedure, that retrieve all friends of a user giving its id...

```
CREATE OR REPLACE FUNCTION sp_getfriends(IN id integer, OUT id integer, OUT username character varying, OUT firstname character varying, OUT lastname character varying, OUT facebook_id character varying)
  RETURNS SETOF record AS
$BODY$SELECT id, username, firstname, lastname, facebook_id
FROM users
LEFT JOIN friends ON users.id = friends.friend_with_id
WHERE friends.user_id = $1$BODY$
  LANGUAGE sql VOLATILE
  COST 100
  ROWS 1000;
```

...we will have a `SP_Getfriends` class generated. We can use it like this :

```
$userId = 20;
$friends = SP_Getfriends::execute($userId);

$firstFriend = $friends[0];
$friend->getId();
$friend->getUsername();
$friend->getFacebookid();
```

[![Bitdeli Badge](https://camo.githubusercontent.com/712614d4ebb390d469e5049df88e8aa3c70dc7602277d59b5eba1c84b18d8ef7/68747470733a2f2f64327765637a68766c38323376302e636c6f756466726f6e742e6e65742f6d72626c61636b75732f6c61726176656c2d73746f72656470726f636564757265732f7472656e642e706e67)](https://bitdeli.com/free "Bitdeli Badge")

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~70 days

Total

3

Last Release

4183d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ea04b0b553a78318976011a0b3c03b2382e7e5d9782cf8dcd7395743d45e3e55?d=identicon)[mrblackus](/maintainers/mrblackus)

---

Top Contributors

[![mrblackus](https://avatars.githubusercontent.com/u/2353980?v=4)](https://github.com/mrblackus "mrblackus (18 commits)")[![bitdeli-chef](https://avatars.githubusercontent.com/u/3092978?v=4)](https://github.com/bitdeli-chef "bitdeli-chef (1 commits)")

### Embed Badge

![Health badge](/badges/mrblackus-laravel-storedprocedures/health.svg)

```
[![Health](https://phpackages.com/badges/mrblackus-laravel-storedprocedures/health.svg)](https://phpackages.com/packages/mrblackus-laravel-storedprocedures)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
