简体   繁体   中英

Check if empty/null column exists in Laravel

I want to check if a row of my Compagny table contains empty or null column, in order to display a message to invite the user to fill his compagny's profile.

Is there a clean and fast way to do that in laravel controller ? Or do I have to do

if(empty($compagny->columnName) || empty($compagny->columnName))
    //content displaying view and message here

And do this for each column in my table ?

Try this...

You can see that Eloquent returns a collection object - an object always passes an empty() check as True. Instead, do

if ( ! $compagny->isEmpty() )

Or even

if ( $compagny->count() )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM