In cases where you're using data sharding to distribute your data across multiple databases, you might have different models that map to different shards. By overriding the $connection property, you can easily manage these connections and ensure your models are interacting with the appropriate databases. If your application uses multiple database connections (e.g., MySQL, PostgreSQL, or different instances of the same database), you may want to specify which connection should be used for a particular model. Here are a few use cases where you might find it especially handy: 1. Overriding the database connection attribute for individual models in Laravel can be a powerful technique. Tip given by Override Connection Attribute in Models $ this-> direction = SortDirections:: Desc,įn () => $query-> orderByDesc( 'avg_rating')įn () => $query-> orderBy( 'avg_rating'), > join( 'product_ratings', 'products.id', '=', 'product_ratings.product_id') > selectRaw( 'AVG(product_ratings.rating) AS avg_rating') Let's write a query for getting today created active and inactive products So, most of the time we use query() method, Typically, we need to query multiple time from a filtered query.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |