0

I hae been recently coding in laravel but I have come across something that I don't really understand that well, how can I run a multiple where clause query with laravel for the below code?

@if ($businesses->where('business_owner_id', '=', Auth::user()->id)->where('business_status', '=', 'accepted')->count() > 0)
                        You own a business...
@elseif ($businesses->where('business_owner_id', '=', Auth::user()->id)->where('business_status', '=', 'pending')->count() > 0)
                        You have a business, but it is currently pending.

  @else
        <p>You can apply to create your own business by clicking the button below.</p>
        <a href="/business/create"><div class="btn btn-default">Create a business</div></a>
  @endif

Error: parse error: syntax error, unexpected ')'

How do I pass the $businesses?

Cache::remember('overview.businesses', 1, function() {
            return Businesses::get();
        });

        return view('frontend.business.overview')->withBusinesses(Cache::get('overview.businesses'));
Amit Gupta
  • 17,072
  • 4
  • 41
  • 53
VoiD HD
  • 699
  • 2
  • 8
  • 18

1 Answers1

1

You better not do those kind of filter/search/calculation on your views, they are supposed to be not intelligent, so I would change it to

$businesses = Cache::remember('overview.businesses', 1, function() {
    return Businesses::get();
});

$acceptedCount = $businesses->where('business_owner_id', '=', Auth::user()->id)->where('business_status', '=', 'accepted')->count();

$pendingCount = $businesses->where('business_owner_id', '=', Auth::user()->id)->where('business_status', '=', 'pending')->count(); 

return view('frontend.business.overview', compact('acceptedCount', 'pendingCount'));

Then you just have to do in your view:

@if ($acceptedCount > 0)
    You own a business...
@elseif ($pendingCount > 0)
    You have a business, but it is currently pending.

@else
    <p>You can apply to create your own business by clicking the button below.</p>
    <a href="/business/create"><div class="btn btn-default">Create a business</div></a>
@endif
Antonio Carlos Ribeiro
  • 86,191
  • 22
  • 213
  • 204