You're selecting from ingredients and doing an inner join on ingredients.
query builder
I 've got a problem with the laravel query builder. I don't understand what 's wrong.
I have 3 tables (salades, ingredients ,salade_ingredient(pivot for n:n relation)
I would like to list the name of ingredients(column ingredients.nom) for salade id 22.
sql query(work well):
select distinct ingredients.nom from ingredients, salade_ingredient,salades where salade_ingredient.salade_id = 22 and ingredients.id = salade_ingredient.ingredient_id
laravel query:
(error:SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'ingredients' (SQL: select ingredients.nom from ingredients inner join salade_ingredient on salade_id = $Salade["id"] inner join ingredients on ingredients.id = salade_ingredient.ingredient_id inner join salades on salade.id = salade_ingredient.salade.id)):):
$Ingredients = DB::table('ingredients') ->select('ingredients.nom') ->join('salade_ingredient', 'salade_id', '=','22') ->join('ingredients', 'ingredients.id', '=', 'salade_ingredient.ingredient_id') ->join('salades','salade.id','=','salade_ingredient.salade_id') ->get()->distinct();
can you help me please? i am new with laravel.
Please or to participate in this conversation.