Skip to content

Laravel Eloquent plugin#1261

Open
AJenbo wants to merge 6 commits intocarthage-software:mainfrom
AJenbo:laravel
Open

Laravel Eloquent plugin#1261
AJenbo wants to merge 6 commits intocarthage-software:mainfrom
AJenbo:laravel

Conversation

@AJenbo
Copy link
Copy Markdown

@AJenbo AJenbo commented Mar 1, 2026

This is a port of my Laravel Eloquent module from https://github.com/AJenbo/phpantom_lsp (including 128 tests)

Hope it can serve as a starting point for solving #885

Test file:

<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    protected function demo(): void
    {
        User::where('id', 1)->firstOrFail();
    }
}

Before:

2026-03-01T21:34:18.634935Z DEBUG main mago::config: Configuration specifies 32 threads.
2026-03-01T21:34:18.634962Z DEBUG main mago::config: Configuration specifies a stack size of 12582912 bytes.
warning[non-documented-method]: Ambiguous method call to `where` on class `App\Models\User`.
   ┌─ app/Models/User.php:11:15
   │
11 │         User::where('id', 1)->firstOrFail();
   │         ----  ^^^^^ This method is not explicitly defined
   │         │      
   │         On an object of type `App\Models\User`
   │
   = While this call might be handled by `__call()` or `__callStatic()`, Mago cannot verify its arguments or return type without a corresponding `@method` docblock tag.
   = Help: To enable full analysis, add a `@method` tag to the docblock of the `App\Models\User` class. For example: `/** @method returnType where(argType $argName) */`

error[mixed-method-access]: Attempting to access a method on a non-object type (`mixed`).
   ┌─ app/Models/User.php:11:31
   │
11 │         User::where('id', 1)->firstOrFail();
   │         --------------------  ^^^^^^^^^^^ Cannot call method here
   │         │                      
   │         This expression has type `mixed`

error: found 2 issues: 1 error(s), 1 warning(s)

After:

2026-03-01T21:34:11.880885Z DEBUG main mago::config: Configuration specifies 32 threads.
2026-03-01T21:34:11.880914Z DEBUG main mago::config: Configuration specifies a stack size of 12582912 bytes.
2026-03-01T21:34:13.887421Z  INFO main mago::service: No issues found.

Comment thread crates/analyzer/src/plugin/libraries/laravel/accessors.rs Outdated
Comment thread crates/analyzer/src/plugin/libraries/laravel/accessors.rs Outdated
@AJenbo
Copy link
Copy Markdown
Author

AJenbo commented Mar 2, 2026

Ok, clippy should be happy now

@AJenbo
Copy link
Copy Markdown
Author

AJenbo commented Mar 2, 2026

I'm refactoring the PHPantom implementation, splitting it up in multiple section. If you prefer I can rework the porting to bring over one part at a time, that should make it easier to review and test.

https://github.com/AJenbo/phpantom_lsp/tree/main/src/virtual_members/laravel

@azjezz
Copy link
Copy Markdown
Member

azjezz commented Mar 3, 2026

@AJenbo small changes would be better indeed.

Otherwise, this PR will be open for weeks until i find the time to review the 5000 changes 😅

And given that i don't use laravel, it would take even more time as i would have to verify every little thing.

@AJenbo
Copy link
Copy Markdown
Author

AJenbo commented Mar 3, 2026

Alright I will do that, at least your not flagging fundamental issues with how I'm trying to bring this over so that's a good start.

@azjezz
Copy link
Copy Markdown
Member

azjezz commented Mar 3, 2026

I don't see any fundamental things i disagree with, but haven't really read it all. the resolved names passing to plugins and codebase metadata to filter hook are fine, could be useful to other plugins too.

@jskorlol
Copy link
Copy Markdown

Does a plugin have to be merged into mago to be usable?
Can't I use an external plugin?

Laravel should support plugins like this.

@azjezz
Copy link
Copy Markdown
Member

azjezz commented Mar 13, 2026

currently no. we don't have external plugin support, but we will probably in the future, i think once the internal plugin API stabilizes, and we are sure it can cover everything we need/want.

@jskorlol
Copy link
Copy Markdown

Thank you always. I'll wait. Until the day I can use it in Laravel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants