1.whereDate() method
<span style="color: #008080;">1</span> <span style="color: #800080;">$q</span>->where('created_at', '>=', <span style="color: #008080;">date</span>('Y-m-d').' 00:00:00'));
In the past, when checking data, I directly used the where condition to compare the values, but the format will have strict requirements. If the third parameter of the above code is date('Y-m-d') without adding the following 00:00:00 In this way, it will not be found in the database
And judging whether they are equal also has strict requirements on the format
<span style="color: #800080;">$q</span>->whereDate('created_at', '=', <span style="color: #008080;">date</span>('Y-m-d'));
Now use whereDate, laravel's own method, which will automatically help you process the date format to ensure that the date matches the search format.
<span style="color: #800080;">$q</span>->whereDay('created_at', '=', <span style="color: #008080;">date</span>('d'<span style="color: #000000;">)); </span><span style="color: #800080;">$q</span>->whereMonth('created_at', '=', <span style="color: #008080;">date</span>('m'<span style="color: #000000;">)); </span><span style="color: #800080;">$q</span>->whereYear('created_at', '=', <span style="color: #008080;">date</span>('Y'));
For example, the above code only searches when the number of days is a certain value. If you use whereDay, it will search the database for a matching value on a certain day.
2.wherePivot() method
Generally, the activity scene of this method is in the model
class Company extends \Eloquent{...
<br> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> memberApplies() { </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->belongsToMany('App\User', 'user_company_applies'<span style="color: #000000;">) </span>->wherePivot('apply_status', UserCompanyApply::<span style="color: #000000;">applyVerify) </span>->wherePivot('type', UserCompanyApply::<span style="color: #000000;">TYPE_USER); }</span>
What does wherePivot mean? , first is the company and user tables, establishing a multi-association relationship, the association table is user_company_applies
First of all, if you don’t add wherePivot, how to display it
The database looks like this
、
Controller:
Display 3 pieces of data,
That is, find the user_id data corresponding to company_id 1 from the intermediate table, and then bring the user_id value to the user table to query what data there is, that is, these 3 items. This is the original many-to-many process
Now the wherePivot method is added, it is nothing more than adding a judgment condition. After obtaining the many-to-many data, then search for the apply_status and type fields in the intermediate table to find which piece of data is 1, and then Show
The database now looks like this
Both the two values are 1. Let’s see if we can query the data with user_id 2525
Start testing
OK

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Atom editor mac version download
The most popular open source editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.