Search by

tobya / anymodel

tobya

Allows creation of a Laravel Entity Model for an arbitrary table

Package info

github.com/tobya/AnyModel

pkg:composer/tobya/anymodel

Statistics

Installs: 4 461

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v1.10 2026-11-09 08:14 UTC

This package is auto-updated.

Last update: 2026-11-09 08:15:43 UTC


README

Allows creation of a Laravel Entity Model for an arbitrary table or view

Allow creation of Laravel Entity Model for any arbitrary table without needing to declare a Model first.

This is particuarily useful if you have a legacy application that uses Views and you do not wish to create a model for each view.

    // return a new model built from vw_ConfirmedBookings table/view
    $Bookings =  AnyModel::table('vw_ConfirmedBookings')
                                  ->where('Confirmed',true)                                  
                                  ->orderBy('updated_at')
                                  ->get();

    // Work with model in normal way
    $Bookings->each(function($Booking){
        AddName( $Booking->name);
    });

Installation

 composer require tobya/anymodel

Concerns

Anymodel package comes with some concerns

use HasNoTable;

use BasedonView;

HasNoTable should be used for a model where you do not wish for a save to be possible. This is useful for Views. BasedonView is an alias for HasNoTable.

use HasCustomPrimaryKey;

Some older tables do not use id as the primary key and the new primary key can be set on the model. However if you call $model->id in your code you will get a null rather than the correct value or an exception. This will correctly return the primaryKey value when $model->id is requested.