Hazel
Hazel

Reputation: 41

How to filter type to display in view

I have a partners-customers table. Every record that is inserted whether is partner (type '1') or customer (type '2') has logo image and a checkbox to decide if the logo will be displayed in the homepage or not.

The homepage has 2 different carousel slide to display partners and customers based on their type.

How do I:

Upvotes: 0

Views: 1508

Answers (2)

NARGIS PARWEEN
NARGIS PARWEEN

Reputation: 1596

The approach should be like this : Controller Function

public function getImage() 
{
    $data = (new PartnersCustomer)->get();
    $customer = data['image'];
    if ($data['type'] == 1) {
        $partner = data['image'];
    }

    return view('index.blade.php')->compact('customer', 'partner');
}

View File

<img src="{{ $customer->path_of_logo}}" />
<img src="{{ $partner->path_of_logo}}" />

Upvotes: 0

Purvesh
Purvesh

Reputation: 646

I would go with this approach:

//My Controller File
public function index() 
{
    // type = 1: partners
    $partners  = PartnersCustomer::whereType(1)->get();

    // type =2 : customers
    $customers = PartnersCustomer::whereType(2)->get();

    return view('my-blade-file-path')->with('partners', $partner)->with('customers' , $customers);
}

Inside your blade template

 <!-- INSIDE YOUR BLADE TEMPLATE -->
@foreach($customers as $customer)

    @if($customer->display_logo == 1)

        <img src="{{ $customer->logo_path}}" />

    @endif

@endforeach

Upvotes: 1

Related Questions