I apologize if this is duplicated. Is it possible in Eloquent ORM to select records where one field equals another? In MySQL this means: Is it possible to do so in Eloquent or I’m bound to using raw queries? Answer On field equalling another in the query builder (and eloquent) is whereColumn(‘Url’, ‘LIKE’, ‘ModelId’) but since you have additional things
Tag: eloquent
How do where one to three values ​come from the combo box in Eloquent Laravel?
I have a filter with three check boxes, each of which has a Value “question”, “partnership”, “complaint”. but when I select two data from the check box (ex.complaint & question) sent to the …
Convert Query to Eloquent
How to make that query with eloquent My relationships I fetching the name with a given ID, but how can I find it for all. Or maybe I am thinking wrong Answer I assumed your employees Model name as Employee and companies Model name as Company If you want to search per id then you may do as below.
changing sql statement to eloquent query
So I have an SQL statement as such; How do I change this to an eloquent query? Or is it better to just use a db:raw query? All inputs are very much appreciated. Cheers! Answer You can try this : Read more at whereBetween section in here
ELOQUENT – Calculating difference of datetimes in where-clause
I am trying to check if the difference of two columns in my database is under a given amount of years – meaning DATETIME – BIRTHDATE where(date_diff((strtotime(‘…
How can this be witten in Laravel Eloquent term?
I am converting a piece of database SQL query to Laravel Eloquent query but it doesn’t work. My code snippet looks like this: Can someone explain why? Answer So assuming you have a Post model, you can try something like this:
Laravel Query. Obtain in Eloquent only totals > 0
I have this query: public static function totalByAgent(int $agentId) { return PropertyListing::select( DB::raw(‘SUM(property_listing.rental) as rental’), DB::raw(‘SUM(…
SQL request with GROUP BY and SUM in Eloquent
I just want make a simple sql request in my laravel application. I’m not very comfortable with Eloquent aha. This is the SQL request I want to make with eloquent : select user_id, project_id, sum(…
Laravel collection how to return where no records and not by auth user
public function tasks(Request $request) { $user = auth::user(); $query = Task::query(); $query->with(‘User’)->with(‘task_type’); $q = $query->paginate($tasksPerPage); …
Convert Raw SQL ‘NOT’ IN (too slow) to Laravel Eloquent
I have a running script using Raw SQL in Laravel 5.3 controller which I found it slow and not secure ( as Raw ). If there any way to make it more effecient and convert it to eloquent or Query Builder …