public function toArray($request)
{
return [
'name' => $this->name,
'email' => $this->email,
'balance' => $this->resource->hasVerifiedEmail()?100:0,
];
}
$students = Students::all()->where('class','=',$i);
$students = Students::where('class','=',$i)->get();
if (isset($i)) {
$students = Students::all()->where('class','=',$i);
} else {
$students = Students::all();
}
$students = Students::when($i, function($builder, $i){ return $builder->where('class', '=', $i); } )->get();
try {
$dbconnect = DB::connection()->getPDO();
$dbname = DB::connection()->getDatabaseName();
} catch(Exception $e) {
return redirect('/exception');
}
class AutoMark extends Model
{
use HasFactory;
public function models()
{
return $this->hasMany(AutoModel::class, 'mark_index', 'index');
}
public function modifications()
{
return $this->hasManyThrough(AutoModification::class, AutoModel::class);
}
}
select table0.user_id, table1.value_1, table2.value_2
from (select user_id from table group by user_id) as table0
left join table as table1 on table0.user_id = table1.user_id AND table1.type = 'remove' and table1.action_type = 3
left join table as table2 on table0.user_id = table2.user_id AND table2.type = 'give' and table2.action_type = 22
Для того, чтобы напрямую изменять элементы массива внутри цикла, переменной $value должен предшествовать знак &. В этом случае значение будет присвоено по ссылке.
foreach ($result as &$article) {
if (mb_stripos($article['title'], 'заголовок', 0, 'UTF-8') !== false) {
$article['image'] = 'images/image.jpg';
}
}
$user = Auth::user();
DB::table('book')
->select('book.*')
->where([
['book.country', '=', $country->id],
['book.city', '=', 0],
['book.approve', '=', 1],
])
->when($user, function($query, $user)
{
$query->leftJoin('favorite', function($query) use($user){
$query->whereColumn('book.id', 'favorite.radio_id')->where('favorite.user_id', '=', $user->id);
})->addSelect('favorite.id as favorite_checked');
})
->paginate(50);
select * from users join (select userid, count(*) as count from fileshare group by userid) as t on users.id = t.userid order by count desc;
select * from users left join (select userid, max(dateupload) as dateupload from fileshare group by userid) as t on users.id = t.userid order by dateupload desc;
->where('status', '=' , 'active')
->whereIn('uid', [2,6])
->get();
->where('status', '=' , 'active')
->where(function($builder){
$builder->where('uid', '=', '2')
->orWhere('uid', '=', '6');
})
->get();
$countries = Country::whereHas('cities', function($builder){
return $builder->where('population', '>', 100000);
})
->with(['cities' => function($builder){
return $builder->where('population', '>', 100000)->orderBy('population', 'asc');
}])
->get();
$items = User::when($request->get('login'), function($query, $login){ $query->where('login', $login) })
->when($request->get('date_start'), function($query, $date_start){ $query->where('date_start', '>=', $date_start) })
->when($request->get('date_end'), function($query, $date_end){ $query->where('date_end', '<=', $date_end) })
->get();
$items = Trip::when($request->get('day_date'), function($query, $date){ $query->where('date', $date); })
->when($request->get('city_departure'), function($query, $departure_id){ $query->where('departure_id', $departure_id); })
->when($request->get('city_arrival'), function($query, $landing_id){ $query->where('landing_id', $landing_id); })
->get();
return view('search')->with(['mass' => $items]);