Extensions for the Eloquent ORM

Related tags

Database eloquence
Overview

Sofa/Eloquence

GitHub Tests Action Status Downloads stable

Easy and flexible extensions for the Eloquent ORM.

Currently available extensions:

  1. Searchable query - crazy-simple fulltext search through any related model
  2. Validable - self-validating models
  3. Mappable -map attributes to table fields and/or related models
  4. Metable - meta attributes made easy
  5. Mutable - flexible attribute get/set mutators with quick setup
  6. Mutator - pipe-based mutating

By installing this package you get aforementioned extensions. Alternatively you can pull just single extension:

# get all extensions
composer require sofa/eloquence 

# get single extension, eg. Metable
composer require sofa/eloquence-metable

Check the documentation for installation and usage info, website for examples and API reference

Contribution

Shout out to all the Contributors!

All contributions are welcome, PRs must be tested and PSR-2 compliant - refer to particular extension repository.

Comments
  • Meta group

    Meta group

    Hey @jarektkaczyk,

    this is my first draft for #131. There are no tests yet. I would like to get your feedback first, if this is a way you would agree with.

    What does it do?

    1. It adds a new column to the table meta_group which is a nullable varchar
    2. when adding a meta item using the setMeta function the user can provide a third argument $group
    3. If none is provided, it is just set to NULL
    4. To get all attributes associated with a group simply use getMetaByGroup('group-name') on your model, which will return a collection of Attributes.
    opened by lukasoppermann 19
  • OrderBy in searchable query builder not working as expected

    OrderBy in searchable query builder not working as expected

    If I insert an orderBy() into a searchable query, the data returned is still ordered by relevance first, and only applies the ordering within groups of results with the same relevance.

    For instance, let's take a basic searchable query:

    Item::search('test')->orderBy('name')->get()
    

    Expected output:

    [
        { name: 'A Item', relevance: 4 }
        { name: 'B Item', relevance: 8 }
        { name: 'C Item', relevance: 4 }
        { name: 'D Item', relevance: 8 }
    ]
    

    Actual output:

    [
        { name: 'B Item', relevance: 8 }
        { name: 'D Item', relevance: 8 }
        { name: 'A Item', relevance: 4 }
        { name: 'C Item', relevance: 4 }
    ]
    

    It still sorts by relevance first before applying the orderBy(). This makes it impossible to sort results alphabetically. If you wanted to order by the relevance and something else then you could always add an orderBy('relevance') into your query, but I don't think this should be forced in if another orderBy statement exists. Can this be fixed easily?

    opened by andynoelker 14
  • Add meta attribute to existing model.

    Add meta attribute to existing model.

    Hey,

    so when I new up a new user I can attach meta attributes, however when I retrieve a user I can not.

    Is this by design? I think it would be pretty useful, as for example with a user you might want to add meta info later on without creating "empty" meta fields on user creation.

    opened by lukasoppermann 13
  • Error with Searchable trait

    Error with Searchable trait

    Hello there,

    I added the searchable columns to my model and added "Customer::search($string)->get();" to my controller, however I'm encountering the following error:

    "SQLSTATE[HY000]: General error: 8120 General SQL Server error: Check messages from the SQL Server [8120](severity 16) [(null)](SQL: select * from %28select [ASC_CUS_TBL_OLD].*, max%28case when [ASC_CUS_TBL_OLD].[CUS_INV_NAME] = OAKWOOD then 15 else 0 end + case when [ASC_CUS_TBL_OLD].[CUS_INV_NAME] like OAKWOOD% then 5 else 0 end + case when [ASC_CUS_TBL_OLD].[CUS_INV_NAME] like %OAKWOOD% then 1 else 0 end%29 as relevance from [ASC_CUS_TBL_OLD] where %28[ASC_CUS_TBL_OLD].[CUS_INV_NAME] like %OAKWOOD%%29 group by [ASC_CUS_TBL_OLD].[CUS_UNIQUE]%29 as [ASC_CUS_TBL_OLD] where [relevance] >= 0.25 order by [relevance] desc)"

    I'm using sqlsrv for the database driver.

    Any ideas? Thanks

    opened by tr33m4n 12
  • Save/Update are not working not working in 5.5

    Save/Update are not working not working in 5.5

    Hi,

    Save/Update are not working for models using eloquence 5.5. It returns as though it saved, but the database record doesn't actually update. Create works fine, just not save & update. I removed the use Eloquence; off the model and the records save/update in the database as expected.

    Are there any additional requirements in 5.5 for that normal functionality to still work? I couldn't see anything in the documentation.

    Thank you!!

    opened by maxvaser 11
  • Xdebug: Maximum function nesting level reached

    Xdebug: Maximum function nesting level reached

    Hello,

    I am having trouble running my PHPunit tests with xdebug on, and I think the problem might come from this package.

    Until a recent change in my code, I had no problems running tests while my models were already using Eloquence. But today, I added 4 classes that inherit my Product model to provide different logics according to the type of product (Ex: AboProduct, StandardProduct...), which I think improves my code.

    Here is how my Product model looks like:

    namespace App;
    
    use Illuminate\Database\Eloquent\Model;
    use Sofa\Eloquence\Eloquence;
    use Sofa\Eloquence\Mappable;
    
    class Product extends Model
    {
        use Eloquence, Mappable;
    
        protected $maps = [
            'name' => 'OLD_NAME',
            'description' => 'OLD_DESCRIPTION',
            'type' => 'OLD_TYPE',
        ];
    
        /**
         * Return an instance of a concrete product class
         * 
         * @return ProductContract
         */
        public function getConcrete()
        {
            $class = $this->resolveProductClass(); // Ex: 'App/AboProduct'
    
            $model = new $class;
            $model->exists = true;
            $model->setRawAttributes((array) $this->getAttributes(), true);
    
            return $model;
        }
    }
    

    Here is how a concrete product class looks like:

    namespace App;
    
    class AboProduct extends Product implements ProductContract
    {
        public function performComplexCalculation()
        {
            // The ProductContract interface requires us to implement this
        }
    }
    

    Here is how my controller looks like

    namespace App\Http\Controllers;
    
    use App\Product;
    
    class ProductController extends Controller
    {
        public function getProductCalculation(Product $product)
        {
            return $product->getConcrete()->performComplexCalculation();
        }
    }
    

    Now, as written above, I am having problems during my tests. Otherwise, everything works as intended. My tests are actually green and run without problem when I run them individually or filtered. It seems that the problem only happens when I run a large part of my test suite.

    Here is the error that I get:

    Fatal error: Maximum function nesting level of '256' reached, aborting! in /var/www/html/vendor/sofa/hookable/src/ArgumentBag.php on line 55
    

    And here an extract of the stack trace (the last traces before it fails):

    ...
    27.2507   75173272 200. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2507   75173272 201. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2507   75173336 202. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2507   75173336 203. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2507   75173400 204. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2507   75173400 205. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2507   75173464 206. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2507   75173464 207. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2507   75173528 208. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2507   75173528 209. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2507   75173592 210. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2507   75173592 211. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2507   75173656 212. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2507   75173656 213. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2507   75173720 214. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2507   75173720 215. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2507   75173784 216. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2507   75173784 217. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2507   75173848 218. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2507   75173848 219. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2507   75173912 220. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2507   75173912 221. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2507   75173976 222. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2507   75173976 223. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2507   75174040 224. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2507   75174040 225. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2507   75174104 226. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2507   75174104 227. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2508   75174168 228. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2508   75174168 229. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2508   75174232 230. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2508   75174232 231. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2508   75174296 232. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2508   75174296 233. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2508   75174360 234. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2508   75174360 235. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2508   75174424 236. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2508   75174424 237. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2508   75174488 238. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2508   75174488 239. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2508   75174552 240. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2508   75174552 241. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2508   75174616 242. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2508   75174616 243. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2508   75174680 244. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2508   75174680 245. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2508   75174744 246. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2508   75174744 247. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2508   75174808 248. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2508   75174808 249. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2508   75174872 250. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2508   75174872 251. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2508   75174936 252. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2508   75174936 253. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2508   75175000 254. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    27.2508   75175000 255. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
    27.2508   75175064 256. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
    

    I don't really know what is going on, but seeing this stack trace I think here could be the right place to ask. I also suspect this might be related to #96 of @maltsev;

    Hopefully someone can help :) Thanks

    Please note that I'm using the v5.2.5 of Eloquence.

    opened by LaurentEsc 10
  • Eloquence Model doesn't work well with Validable?

    Eloquence Model doesn't work well with Validable?

    When my model code is this, seeding doesn't work

    <?php namespace App;
    
    use Sofa\Eloquence\Model;
    use Sofa\Eloquence\Mutable;
    
    class LetterType extends Model {
    
        use Mutable;
    
        protected $fillable = ['title', 'acronym', 'description'];
    
        /**
         * Attributes getter mutators @ Eloquence\Mutable
         *
         * @var array
         */
        protected $getterMutators = [
    
        ];
    
        /**
         * Attributes setter mutators @ Eloquence\Mutable
         *
         * @var array
         */
        protected $setterMutators = [
            'acronym' => 'trim',
        ];
    
        protected static $rules = [
            'title'  => 'required',
            'acronym' => 'required',
        ];
    }
    

    Seeding only works when I change to:

    <?php namespace App;
    
    use Illuminate\Database\Eloquent\Model;
    use Sofa\Eloquence\Contracts\CleansAttributes;
    use Sofa\Eloquence\Contracts\Validable as ValidableContract;
    use Sofa\Eloquence\Eloquence;
    use Sofa\Eloquence\Mappable;
    use Sofa\Eloquence\Mutable;
    use Sofa\Eloquence\Validable;
    
    class LetterType extends Model implements ValidableContract, CleansAttributes {
    
        use Eloquence, Mutable, Validable;
    
        protected $fillable = ['title', 'acronym', 'description'];
    
        /**
         * Attributes getter mutators @ Eloquence\Mutable
         *
         * @var array
         */
        protected $getterMutators = [
    
        ];
    
        /**
         * Attributes setter mutators @ Eloquence\Mutable
         *
         * @var array
         */
        protected $setterMutators = [
            'acronym' => 'trim|strtoupper',
        ];
    
        /**
         * Rules for field attributes
         * Available rules as described in the laravel docs:
         * @link http://laravel.com/docs/5.0/validation#available-validation-rules
         */
        public static $rules = [
            'title'  => 'required',
            'acronym' => 'required',
    
        ];
    
    }
    

    This is strange to me because for my User model, extending Sofa\Eloquence\Model gives me no issue in seeding. But for my LetterType model, it does.

    opened by ziming 10
  • Compatibility with Fractal

    Compatibility with Fractal

    Hi there,

    I really appreciate eloquence — so thanks for providing it! However, I came across one thing when using Mappable in conjunction with Fractal (https://github.com/thephpleague/fractal) in my Lumen API: When calling the toArray() Method on my model, the mapped fields aren't returned. I'm sure I'm doing something wrong here so I'd appreciate a hint into the right direction.

    My code looks something like this

    class TestModel extends Model implements ... {
       use Eloquence, Mappable;
       protected $maps = [
           'mapped_field' => 'original_field',
           ...
       ]
    }
    
    class TestTransformer extends Fractal\TransformerAbstract {
       public function transform (TestModel $test) {
          return $test->toArray();
       }
    }
    

    This would return something like

    array(original_field => "value");
    // instead of 
    array(mapped_field => "value");
    

    Thanks!

    opened by mmaedler 8
  • Support for Laravel 5.2

    Support for Laravel 5.2

    When I upgrade to Laravel 5.2. I noticed a compile error in Builder.php File Sofa \ Hookable package. Stating that the implementation of the method "pluck" should be consistent with the implementation of the file "Illuminate \ Database \ Eloquent \ Builder".

    I realized that at that lacked a parameter ($ key) in the method signature.

    I did the manual implementation. But I wonder when we update the version of eloquence with all that it takes.

    opened by JoseClaudioADS 8
  • Add Formattable Trait

    Add Formattable Trait

    Hey @jarektkaczyk!

    :construction: We have collision problems with our method setAttribute. How can we handle that?

    With that we can easily format our attributes.

    class User
    {
        use Formattable;
    
        protected $formats = [
            'first_name' => ['strtolower', 'ucwords],
            'last_name' => 'strtolower|ucwords',
            'phone' => 'formatPhone',
            'slug' => '\Str@slug',
        ];
    
        public function formatPhone($phone)
        {
            return "({$phone})";
        }
    }
    
    $user->first_name = 'roMAin'; // Will set 'Romain'
    $user->last_name = 'laNZ'; // Will set 'Lanz'
    $user->phone = 555; // Will set '(555)'
    $user->slug = 'Awesome package!'; // Will set 'awesome-package'
    

    I also change the readme to be better and to document Formattable.

    opened by RomainLanz 8
  • Multiple meta elements of same type

    Multiple meta elements of same type

    Hey @jarektkaczyk,

    how can I add 2 meta items of the same type to the same model?

    For example I am trying to add favorite_color to a user model. However I want the user to be able to define multiple colors. How can I do this and how can I retrieve them?

    E.g. user 1 -> color: red and color: blue

    Thank you.

    opened by lukasoppermann 7
  • Searchable and multiple keywords positioning

    Searchable and multiple keywords positioning

    Hi,

    when I search by multiple keywords f.ex.:

    Car::search('toyota hybrid', ['name' => 10], true)->get();
    

    the results contanins occurance of "*toyota*" or "*hybrid*" with the same weight so the list looks like this:

    1. Toyota Camry
    2. Toyota Prius Hybrid
    

    Shouldn''t result be in the order:

    1. Toyota Prius Hybrid
    2. Toyota Camry
    

    because name Toyota Prius Hybrid have 2 hits while Toyota Camry is only 1 hit? Or is that possible to configure that all keywords should be hit?

    opened by GrzegorzP 0
  • Issue with Nova - Call to undefined method Sofa\\Eloquence\\Query\\Builder::getModel()

    Issue with Nova - Call to undefined method Sofa\\Eloquence\\Query\\Builder::getModel()

    I tried using the Mappable package on a basic model user. Upon trying to use the search field, it returns the following :

    Call to undefined method Sofa\\Eloquence\\Query\\Builder::getModel()
    

    Also the ressource will simply not load (without throwing any error, nor logging any!)

    Here's my model definition:

    <?php
    
    namespace App\Models;
    
    use Illuminate\Database\Eloquent\Factories\HasFactory;
    use Illuminate\Foundation\Auth\User as Authenticatable;
    use Illuminate\Notifications\Notifiable;
    use Sofa\Eloquence\Eloquence;
    use Sofa\Eloquence\Mappable;
    
    class User extends Authenticatable
    {
        use HasFactory, Notifiable, Eloquence, Mappable;
    
        protected $maps = [
            'id' => 'usrID',
            'username' => 'usrPseudo',
            'first_name' => 'usrFirstName',
            'last_name' => 'usrLastName',
            'password' => 'usrPassword',
            'email' => 'usrEMail',
            'role' => 'usrRole',
            'updated_at' => 'userLastModified',
            'code' => 'ecritureGL',
        ];
    }
    

    Any ideas?

    opened by villeneuve-michael 1
  • Laravel 9 - xdebug infinite loop

    Laravel 9 - xdebug infinite loop

    Laravel version 9.0 PHP: 8.0

    I just upgraded our project to L9 but eloquence is causing xdebug error: Xdebug has detected a possible infinite loop, and aborted your script with a stack depth of '1000' frames

    As soon as I remove eloquence from model it's working fine.

    Any idea what is causing the problem?

    opened by svkmedia 2
  • Order by relevance

    Order by relevance

    Hello, I have for example this articles:

    1. xbox system update beta
    2. nintendo system update beta
    3. ps4 system update games
    4. ps5 system best games

    if search for example: 'system best games' or 'best games system'

    Is possible to order by relevance like this?

    1. ps5 system best games
    2. ps4 system update games
    3. xbox system update beta
    4. nintendo system update beta

    this is my eloquent query:

    $search = $request->input('s');
    return Post::search(''.$search.'', ['name' => 10])
                       ->paginate(10);
    
    

    thanks so much!

    opened by cloudeweb 1
  • Mappable + Multiple Wheres

    Mappable + Multiple Wheres

    When you try to use mappable and logical grouping the mappable fields won't work.

    https://laravel.com/docs/8.x/queries#logical-grouping

    class MyModel {
      use Eloquence, Mappable;
     protected $maps = [
            'id'               => 'myId',
            'field1'         => 'myField1',
            'field2'         => 'myField2',
            'is_enabled' => 'enabled'
        ];
    
    }
    
    $this->queryBuilder = MyModel::query();
    $this->queryBuilder->where('is_enabled', 1);
    $this->queryBuilder->where(function ($query) use ($searchCriteria) {
                    $text = '%'.Arr::pull($searchCriteria, 'text').'%';
                    return $query->where('field1', 'LIKE', $text)
                    ->orWhere('field2', 'LIKE', $text);
    });
    $this->queryBuilder->get();
    

    Error: SQLSTATE[42S22]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid column name 'field1'.

    opened by gfernandez-me 2
Owner
Jarek Tkaczyk
Jarek Tkaczyk
Baum is an implementation of the Nested Set pattern for Laravel's Eloquent ORM.

Baum Baum is an implementation of the Nested Set pattern for Laravel 5's Eloquent ORM. For Laravel 4.2.x compatibility, check the 1.0.x branch branch

Estanislau Trepat 2.2k Jan 3, 2023
Simple Enum cast for Eloquent ORM using myclabs/php-enum.

Enum cast for Eloquent Simple Enum cast for Eloquent ORM using myclabs/php-enum. Requirements PHP 7.3 or higher Laravel 8.0 or higher Installation You

Orkhan Ahmadov 5 Apr 21, 2022
Doctrine Object Relational Mapper (ORM)

3.0.x 2.9.x 2.8.x Doctrine 2 is an object-relational mapper (ORM) for PHP 7.1+ that provides transparent persistence for PHP objects. It sits on top o

Doctrine 9.5k Jan 2, 2023
ORM layer that creates models, config and database on the fly

RedBeanPHP 5 RedBeanPHP is an easy to use ORM tool for PHP. Automatically creates tables and columns as you go No configuration, just fire and forget

Gabor de Mooij 2.2k Jan 9, 2023
Propel2 is an open-source high-performance Object-Relational Mapping (ORM) for modern PHP

Propel2 Propel2 is an open-source Object-Relational Mapping (ORM) for PHP. Requirements Propel uses the following Symfony Components: Config Console F

Propel 1.2k Dec 27, 2022
PHP DataMapper, ORM

Cycle ORM Cycle is PHP DataMapper, ORM and Data Modelling engine designed to safely work in classic and daemonized PHP applications (like RoadRunner).

Cycle ORM 1.1k Jan 8, 2023
A drop-in Doctrine ORM 2 implementation for Laravel 5+ and Lumen

Laravel Doctrine ORM A drop-in Doctrine ORM 2 implementation for Laravel 5+ $scientist = new Scientist( 'Albert', 'Einstein' ); $scientist->a

Laravel Doctrine 777 Dec 17, 2022
Ouzo Framework - PHP MVC ORM

Ouzo is a PHP MVC framework with built-in ORM and util libraries. PHP 8.0 or later is required. We believe in clean code and simplicity. We value unit

Ouzo 69 Dec 27, 2022
Builds Cycle ORM schemas from OpenAPI 3 component schemas

Phanua OpenAPI 3 + Jane + Cycle ORM = ?? Phanua builds Cycle ORM schemas from OpenAPI 3 component schemas. Released under the MIT License. WARNING: Th

Matthew Turland 5 Dec 26, 2022
Extra RedBean ORM

RedBeanPHP 5 RedBeanPHP is an easy to use ORM tool for PHP. Automatically creates tables and columns as you go No configuration, just fire and forget

GingTeam Development 5 Nov 23, 2022
Articulate - An alternative ORM for Laravel, making use of the data mapper pattern

Articulate Laravel: 8.* PHP: 8.* License: MIT Author: Ollie Read Author Homepage: https://ollie.codes Articulate is an alternative ORM for Laravel bas

Ollie Codes 4 Jan 4, 2022
MongoDB ORM that includes support for references,embed and multilevel inheritance.

Introduction Features Requirements Installation Setup Database Basic Usage - CRUD Relationship - Reference Relationship - Embed Collection Inheritance

Michael Gan 202 Nov 17, 2022
Low code , Zero Configuration ORM that creates models, config, database and tables on the fly.

?? ARCA ORM ?? Low code , Zero Configuration ORM that creates models, config, database and tables on the fly. ?? ???? Made in India ???? Complete docu

Scrawler Labs 28 Dec 18, 2022
The Enobrev\ORM library is a small framework of classes meant to be used for simply mapping a mysql database to PHP classes, and for creating simply SQL statements using those classes.

The Enobrev\ORM library is a small framework of classes meant to be used for simply mapping a mysql database to PHP classes, and for creating simply SQL statements using those classes.

Mark Armendariz 0 Jan 7, 2022
Orm is a simple database abstraction layer that supports postgresql.

Orm What is it Orm is a simple database abstraction layer that supports postgresql. Welcome to join us or star us for encouragement. Requires php 8.1

null 2 Sep 28, 2022
Doctrine2 behavioral extensions, Translatable, Sluggable, Tree-NestedSet, Timestampable, Loggable, Sortable

Doctrine Behavioral Extensions This package contains extensions for Doctrine ORM and MongoDB ODM that offer new functionality or tools to use Doctrine

Doctrine Extensions 3.8k Jan 5, 2023
Doctrine2 behavioral extensions, Translatable, Sluggable, Tree-NestedSet, Timestampable, Loggable, Sortable

Doctrine Behavioral Extensions This package contains extensions for Doctrine ORM and MongoDB ODM that offer new functionality or tools to use Doctrine

Doctrine Extensions 3.8k Jan 5, 2023
⚡️ Models like Eloquent for Elasticsearch.

Elasticsearch Eloquent 2.x This package allows you to interact with Elasticsearch as you interact with Eloquent models in Laravel. Requirements PHP >=

Sergey Sorokin 111 Dec 19, 2022
A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)

Laravel MongoDB This package adds functionalities to the Eloquent model and Query builder for MongoDB, using the original Laravel API. This library ex

Jens Segers 6.3k Jan 5, 2023