Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

328
Views
Laravel: No obtener los datos requeridos

Soy un novato de Laravel, así que no entiendo por qué esta consulta me da solo un resultado de usuario en lugar de todas las entradas que contienen posts.title o posts.description . Esta debería ser una expresión de búsqueda ( %for% ) y usar la categoría específica ( get ).

 DB::table('posts') ->join('users', 'users.id', '=', 'posts.user_id') ->join('locations', 'users.id', '=', 'locations.id') ->join('main_categories', 'main_categories.id', '=', 'posts.main_category_id') ->select('posts.*', 'users.*', 'locations.address', 'main_categories.name as cat', DB::raw('ROUND((6371 * ACOS(COS(RADIANS(31.430443800000003)) * COS(RADIANS(locations.lattitude)) * COS(RADIANS(locations.longitude) - RADIANS(74.280726)) + SIN(RADIANS(31.430443800000003)) * SIN(RADIANS(locations.lattitude)))),2) AS DISTANCE')) ->where([['posts.title','like','%for%'],['main_categories.name', '=', 'get']]) ->orwhere([['posts.description','like','%for%'],['main_categories.name', '=', 'get']]) ->get();

Estoy tratando de convertir esta consulta MySQL en formato Laravel. Esta consulta de MySQL me da 3 filas, 2 de un usuario y 1 fila de otro usuario. Pero en Laravel solo obtengo una fila de usuario.

 SELECT posts.title, posts.description, posts.sub_category_id, posts.image, posts.created_at, posts.main_category_id, posts.user_id, locations.address, ROUND( ( 6371 * ACOS( COS(RADIANS(31.430443800000003)) * COS(RADIANS(locations.lattitude)) * COS( RADIANS(locations.longitude) - RADIANS(74.280726) ) + SIN(RADIANS(31.430443800000003)) * SIN(RADIANS(locations.lattitude)) ) ), 2 ) AS DISTANCE FROM posts INNER JOIN users ON posts.user_id = users.id INNER JOIN locations ON users.location_id = locations.id INNER JOIN main_categories ON main_categories.id = posts.main_category_id WHERE ( ( posts.title LIKE '%for%' OR posts.description LIKE '%for%' ) AND(main_categories.name = 'Get') )
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Usas una unión no válida en tu consulta de Laravel. En vez de

 ->join('locations', 'users.id', '=', 'locations.id')

debería ser

 ->join('locations', 'users.location_id', '=', 'locations.id')

porque en tu consulta sin procesar usas:

 INNER JOIN locations ON users.location_id = locations.id
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!