Giter Club home page Giter Club logo

Comments (4)

fico7489 avatar fico7489 commented on June 28, 2024 1

both models should use EloquentJoinTrait so you need to user EloquentJoinTrait in Work model also, but a better solution would be to create BaseModel model which extends Model, use EloquentJoinTrait in BaseModel and then both models can extend BaseModel, not Model.

PS. I will update the docs so this will be more clear...

from laravel-eloquent-join.

fico7489 avatar fico7489 commented on June 28, 2024

@ergonomicus can you paste your relation functions in models on which you are performing queries, table names of models, and query code?

from laravel-eloquent-join.

ergonomicus avatar ergonomicus commented on June 28, 2024

@fico7489 I can paste only parts of code, it's an internal app...

Here are my models

// Event model
use Illuminate\Database\Eloquent\Model;
use App\Models\Work;
use Fico7489\Laravel\EloquentJoin\Traits\EloquentJoinTrait;

class Event extends Model
{
    // table 'events'
    use EloquentJoinTrait;

    public function work()
    {
        return $this->belongsTo(Work::class);
    }

    // bunch of other relations and accessors...
}

// Work model
use Illuminate\Database\Eloquent\Model;
use App\Models\Event;

class Work extends Model
{
    // table 'works'

    public function events()
    {
        return $this->hasMany(Event::class);
    }

    // bunch of other relations and accessors...
}

Here is my controller method

    public function index()
    {
        // works table has a boolean field 'is_archived' and datetime field 'start'
        $events = Event::with('eventStatus', 'work.customer.address')->orderByJoin('work.is_archived')->orderBy('start')->get();
        
        return view('events.index', compact('events'));
    }

Laravel 5.5.latest and PHP 7.1.12

Thanks.

from laravel-eloquent-join.

ergonomicus avatar ergonomicus commented on June 28, 2024

@fico7489 Ok, thank you. I will try again...

from laravel-eloquent-join.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.