Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

karresachi's avatar

Inertia filters trashed

Hello,

I am getting null when I Request::all('search', 'trashed'), but there are deleted Employees.

Am I missing something?

Employee Model  
  
  
namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;

class Employee extends Model
{
    use SoftDeletes, HasFactory;

    protected $guarded = [];

    protected $dates = [
        'created_at',
        'updated_at',
        'deleted_at'
    ];

    protected $fillable = [
        'business_id',
        'name',
        'email',
        'phone',
        'role',
        'services',
    ];


    public function getNameAttribute()
    {
        return $this->name.' '.$this->phone;
    }

    public function scopeOrderByName($query)
    {
        $query->orderBy('name')->orderBy('role');
    }

    public function scopeFilter($query, array $filters)
    {
        $query->when($filters['search'] ?? null, function ($query, $search) {
            $query->where(function ($query) use ($search) {
                $query->where('name', 'like', '%'.$search.'%')
                    ->orWhere('phone', 'like', '%'.$search.'%')
                    ->orWhere('email', 'like', '%'.$search.'%');
            });
        })->when($filters['trashed'] ?? null, function ($query, $trashed) {
            if ($trashed === 'with') {
                $query->withTrashed();
            } elseif ($trashed === 'only') {
                $query->onlyTrashed();
            }
        });
    }
}
EmployeeController 

namespace App\Http\Controllers;

use App\Models\Employee;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Request;

use Inertia\Inertia;

class EmployeeController extends Controller
{
    public function index()
    {
        $user = auth()->user()->business->id;

        $test = Request::all('search', 'trashed');
        dd($test);
        return Inertia::render('Admin/Employee/Index', [
            'filters' => Request::all('search', 'trashed'), // <-- this gives null but there is 1 deleted employee
            'employees' => Employee::where('business_id', $user)
                ->orderByName()
                ->filter(Request::only('search', 'trashed'))
                ->paginate()
                ->withQueryString()
                ->through(function ($employee) {
                    return [
                        'id' => $employee->id,
                        'name' => $employee->name,
                        'email' => $employee->email,
                        'phone' => $employee->phone,
                        'services' => $employee->services,
                        'role' => $employee->role,
                        'deleted_at' => $employee->deleted_at,
                    ];
                })
        ]);
    }

}
0 likes
3 replies
karresachi's avatar

When I dd Request::all('search', 'trashed')

array:2 [▼
  "search" => null
  "trashed" => null
]
karresachi's avatar

Sorry maybe it is supposed to be null, but I get this error

Error in nextTick: "TypeError: Cannot read property 'setAttribute' of undefined  
found in

---> <Dropdown> at resources/js/Shared/Dropdown.vue
Dropdown.vue 

<template>
  <button type="button" @click="show = true">
    <slot />
    <portal v-if="show" to="dropdown">
      <div>
        <div style="position: fixed; top: 0; right: 0; left: 0; bottom: 0; z-index: 99998; background: black; opacity: .2" @click="show = false" />
        <div ref="dropdown" style="position: absolute; z-index: 99999;" @click.stop="show = autoClose ? false : true">
          <slot name="dropdown" />
        </div>
      </div>
    </portal>
  </button>
</template>

<script>
import Popper from 'popper.js'
export default {
  props: {
    placement: {
      type: String,
      default: 'bottom-end',
    },
    boundary: {
      type: String,
      default: 'scrollParent',
    },
    autoClose: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      show: false,
    }
  },
  watch: {
    show(show) {
      if (show) {
        this.$nextTick(() => {
          this.popper = new Popper(this.$el, this.$refs.dropdown, {
            placement: this.placement,
            modifiers: {
              preventOverflow: { boundariesElement: this.boundary },
            },
          })
        })
      } else if (this.popper) {
        setTimeout(() => this.popper.destroy(), 100)
      }
    },
  },
  mounted() {
    document.addEventListener('keydown', e => {
      if (e.keyCode === 27) {
        this.show = false
      }
    })
  },
}
</script>


Please or to participate in this conversation.