mercredi 4 décembre 2019

Laravel 5.0: How to filter the collection results based on status

I have a database of machines, i want them to hide when the status = "disabled", i know about soft delete but i still want the admins to have access to those machines even tho they wont show up on this specific view, so they can't be deleted.

here's the controller function

    public function home(Request $request)
{
    $user = Auth::user();
    switch ($user->tipo) {
        case 'admin':
            $title = 'Máquinas';
            $maquinas = Maquinas::all();
            $admin = true;
            break;
        case 'cliente':
            $cliente = Clientes::find($user->cliente_id);
            $title = $cliente->empresa.' <i class="fa fa-arrow-right" style="font-size: 20px; color: gray"></i> Máquinas';
            $maquinas = $cliente->maquinas()->get();
            $admin = false;
            break;
        case 'base':
            $cliente = Clientes::find($user->cliente_id);
            $base = Bases::find($user->base_id);
            $title = $cliente->empresa.' <i class="fa fa-arrow-right" style="font-size: 20px; color: gray"></i> '.$base->nome.' <i class="fa fa-arrow-right" style="font-size: 20px; color: gray"></i> Máquinas';
            $maquinas = $base->maquinas()->get();
            $admin = false;
            break;
        default:
            # code...
            break;
    }

i want to filter the disabled ones on case 'cliente' and case 'base'



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire