“filter Laravel” Kode Jawaban

koleksi filter laravel

$collection = collect([1, 2, 3, 4]);

$filtered = $collection->filter(function ($value, $key) {
    return $value > 2;
});

$filtered->all();

// [3, 4]
Relieved Raccoon

filter Laravel

<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;

class UserController extends Controller
{
    public function index(Request $request)
    {
        $users = User::where('is_active', true);

        if ($request->has('age_more_than')) {
            $users->where('age', '>', $request->age_more_than);
        }

        if ($request->has('gender')) {
            $users->where('gender', $request->gender);
        }

        if ($request->has('created_at')) {
            $users->where('created_at','>=', $request->created_at);
        }

        return $users->get();
    }
}
Shadow

Jawaban yang mirip dengan “filter Laravel”

Pertanyaan yang mirip dengan “filter Laravel”

Lebih banyak jawaban terkait untuk “filter Laravel” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya