PHP code example of nullthoughts / laravel-latest-relation
1. Go to this page and download the library: Download nullthoughts/laravel-latest-relation library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nullthoughts / laravel-latest-relation example snippets
public function scopeUsingDevice($query, $device)
{
return $query->whereLatestRelation('logins', 'device_type', $device);
}
public function scopeHavingCountry($query)
{
return $query->whereLatestRelation('logins', 'country', '!=', 'null');
}
$users = User::whereHas('logins', function ($query) {
$query->whereLatest('device_type', 'desktop');
});
public function scopeUsingDevice($query, $device)
{
return $query->whereHas('logins', function ($query) use ($device) {
$query->whereLatest('device_type', $device);
});
}
public function scopeHavingDeviceType($query)
{
return $query->whereHas('logins', function ($query) {
$query->latestRelation()->whereNotNull('device_type');
});
}