
Erro al hacer join con 3 tablas
Publicado por Luis (1 intervención) el 19/01/2019 15:40:58
Lo que quiero hacer es traer los datos de tablas y que lo pueda mostrar en un grilla(en este caso seria la alert()) que le puse para pobrar si funcionaba
MI función buscar
mi ajax
mi ruta
mi modelo
MI función buscar
1
2
3
4
5
6
7
8
9
10
11
12
13
public function search(Request $request){
$company=request::get('cliente');//recuperodatosenvporgetopost.
$dni=request::get('search')
$heads =DB::table('heads')
->join('participants', 'heads.id','=','participants.head_id')
->join('companies','company.id','=','companies.id')
->select('companies.name as nom_com','participants.firstlastname as ape_pat','participants.secondlastname as ape_mat','participants.name
as nombre','companies.created_at as fec1','companies.updated_at as fec2')
->where('companies.company_id',$company)
->where('dni',$dni)
->get();
return Response::json('heads');
}
mi ajax
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<script type="text/javascript">
//comprobamos si el dni Y la compañia existe en la base de datos
$("#search"&&"#cliente" ).on('blur',function(){
if( $("#search").val().length <8&&$("#cliente").val().length !=0)
{
$("#resultado").html('<div class="alert alert-danger"> Rellene todos los campos.</div>');
} else{
$("#resultado").html("");
var cliente=$('#cliente').val();
var search=$('#search').val();
//$value=$(this).val(); //->/objeto query
$.ajax({
type:'get',
url : '/welcome',
data:{'company':cliente,'dni':search},
dataType:'json',
beforeSend: function(){
$('#resultado').append('<i class="fa fa-cog fa-spin fa-3x fa-fw"></i><span class="sr-only">Loading...</span>');
},
success:function(data){
if( data!=null){
alert('hola');
}
else {
$('#resultado').html('<div class="alert alert-danger"><strong><i class="fa fa-frown-o" aria-hidden="true"></i> Error!</strong> Aun no cuenta con un certificado.</div>');
}
}
});
return false;
return false;
}
});
</script>
<script type="text/javascript">
$.ajaxSetup({ headers: { 'csrftoken' : '{{ csrf_token() }}' } });
</script>
mi ruta
1
2
Route::get('/welcome','UserController@index');
Route::get('/users','UserController@search');
mi modelo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
protected $fillable = [
'name', 'email', 'password',
];
protected $hidden = [
'password', 'remember_token',
];
}
Valora esta pregunta


0