0

I am beginner php developer.

I have this code:

Model::selectRaw('clients.*, if((client_company_infos.name != "" , client_company_infos.type == 1),  client_company_infos.name, concat(client_infos.first_name, " ", client_infos.last_name)) as name')
            ->leftJoin('client_company_infos', 'client_company_infos.client_id', '=', 'clients.id')
            ->leftJoin('client_infos', 'client_infos.client_id', '=', 'clients.id')
            ->get();

I have error:

"message": "SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '== 1), client_company_infos.name, concat(client_infos.first_name, " ", client_i' at line 1 (SQL: select clients.*, if((client_company_infos.name != "" , client_company_infos.type == 1), client_company_infos.name, concat(client_infos.first_name, " ", client_infos.last_name)) as name from clients left join client_company_infos on client_company_infos.client_id = clients.id left join client_infos on client_infos.client_id = clients.id where clients.deleted_at is null)",

When I make:

Model::selectRaw('clients.*, if(client_company_infos.name != "",  client_company_infos.name, concat(client_infos.first_name, " ", client_infos.last_name)) as name')
            ->leftJoin('client_company_infos', 'client_company_infos.client_id', '=', 'clients.id')
            ->leftJoin('client_infos', 'client_infos.client_id', '=', 'clients.id')
            ->get();

It's work fine. Problem. I with second if. How can I. repair it?

Please help me

1
  • 1
    The equal operator in MySQL is =, not ==. Commented Oct 20, 2020 at 10:24

1 Answer 1

2

There is no operator == in MySql.

You need to replace the condition with the following:

client_company_infos.type = 1
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.