jwz104/eloquent-view

This package is abandoned and no longer maintained. No replacement package was suggested.

Create sql views with eloquent

1.0.0 2017-09-17 19:09 UTC

This package is not auto-updated.

Last update: 2023-12-09 23:12:53 UTC


README

With Eloquent view you can create a SQL view with the eloquent query builder. This will prevent huge SQL strings in your migrations.

Installation

Run composer require jwz104/eloquent-view.

Add the service provider to config/app.php:

'providers' => [
    Jwz104\EloquentView\EloquentViewServiceProvider::class,
]

Optionally add the facade:

'aliases' => [
    'EloquentView' => Jwz104\EloquentView\Facades\EloquentView::class,
]

How to use

Eloquent view is really easy to use.
Just parse a builder instance to the create method of the view builder.

Example migration:

class CreateEmployeesView extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $builder = DB::table('employees')
            ->join('companies', 'employees.company_id', '=', 'companies.id')
            ->select('employees.*', 'companies.name');

        EloquentView::create('employees_view', $builder);
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        EloquentView::dropIfExists('employees_view');
    }
}