More laravel help

Proximity

IDK?
Feb 13, 2014
673
56
I am trying to do a if hiring else not hiring but it isn't working ...

Code:
                                           @if (DB::table('setting')->where('hiring', 1))
                                            
                                              Hiring
                                      
                                            @else
                                            
                                                Not Hiring
                                            
                                            @endif
is my code.
 

Genaga

New Member
Mar 12, 2015
29
8
Is there an error that should up? Are you in a blade there?

Code:
@ if (count(DB::table('setting')->where('hiring', '=', 1)->get()) > 0)
Probably another way to do it but I'm drawing a blank right now.

First errors was forgetting the '=', this is used to determine how you want to search, you can use various operators here. (< > != etc)
Then you forgot to use ->get() which actually retrieves the collection.
Then you wasn't actually checking anything, there is more than one way to do this, but i simply counted the records, if no records showed up (count would be 0) then not hiring.

Hope this is of some help and I'm actually correct, give us a shout if there's anything else!
 

Ollie

Member
Jan 7, 2013
72
11
I believe with my short time working on Laravel that you shouldn't be doing logic like that in Blade anyway? Surely you would pass through to the view from the controller with a ->with() on the end of your view load?
 

Users who are viewing this thread

Top