hola buenos dias, lo que trato de hacer es llamara el nombre de la empresa y el del usuario para mostrarlo en una tabla contenido en index pero me sale este error de la consulta espero y puedan ayudarme
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'empresas.perfil_id' in 'where clause' (SQL: select * from `empresas` where `empresas`.`perfil_id` = 57 and `empresas`.`perfil_id` is not null limit 1) (View: C:\xampp\htdocs\tienda-master\resources\views\auth\index.blade.php).
esta es la tabla que quiero rellenara y en los campos que quiero mostara son de la tabala user el nombre y de la tabala empresa el nombre esas variables estan definidas en mi controlador... que se ve mas abajo..
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Usuario</th>
<th>Empresa</th>
<th>Alta Producto o servicio</th>
<th>Alta de kits</th>
<th>Alta de garantias</th>
<th>Traspasos</th>
<th>Kardex</th>
</tr>
</thead>
<tbody>
@foreach($perfil as $perfils)
<tr>
<td>{{ $perfils->user->name}}</td>
<td>{{ $perfils->empresas->name }}</td>
<td>{{ $perfils->alta_p_s }}</td>
<td>{{ $perfils->alta_kits }}</td>
<td>{{ $perfils->alta_garantia }}</td>
<td>{{ $perfils->traspasos }}</td>
<td>{{ $perfils->kardex }}</td>
<td>
<a class="btn btn-primary">
<i class="fa fa-pencil-square-o"></i>
</a>
</td>
</tr>
@endforeach
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Perfil;
use App\Empresas;
use App\User;
class PerfilController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$user = User::orderBy('id', 'desc')->lists('name', 'id');
$empresas = Empresas::orderBy('id', 'desc')->lists('name', 'id');
$perfil = Perfil::orderBy('id', 'desc')->paginate(5);
return view('auth.perfil',compact('perfil','user', 'empresas'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
$user = User::orderBy('id', 'desc')->lists('name', 'id');
$empresas = Empresas::orderBy('id', 'desc')->lists('name', 'id');
$perfil = Perfil::orderBy('id', 'desc')->paginate(7);
return view( 'auth.index',compact('perfil','user', 'empresas'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$data = [
'alta_p_s' => $request->get('alta_p_s'),
'alta_kits' => $request->get('alta_kits'),
'alta_garantia' => $request->get('alta_garantia'),
'traspasos' => $request->get('traspasos'),
'kardex' => $request->get('kardex'),
'user_id' => $request->get('user_id'),
'empresa_id' => $request->get('empresa_id')
];
$perfil = Perfil::create($data);
$message = $perfil? 'Perfil agregado correctamente!' : 'El perfil NO pudo agregarse!';
return redirect()->route('perfil.create.index')->with('message', $message);
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show(Perfil $perfils)
{
//
return $perfils;
}
/**
espero y puedan ayudarme
ErrorException in Connection.php line 651:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'empresas.perfil_id' in 'where clause' (SQL: select * from `empresas` where `empresas`.`perfil_id` = 64 and `empresas`.`perfil_id` is not null) (View: C:\xampp\htdocs\tienda-master\resources\views\auth\index.blade.php)
in Connection.php line 651
at CompilerEngine->handleViewException(object(QueryException), '1') in PhpEngine.php line 44
at PhpEngine->evaluatePath('C:\xampp\htdocs\tienda-master\storage\framework\views/0316f17c9c7474e6582b2f41b13cdfc0', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'perfil' => object(LengthAwarePaginator), 'user' => object(Collection), 'empresas' => object(Collection))) in CompilerEngine.php line 58
at CompilerEngine->get('C:\xampp\htdocs\tienda-master\resources\views/auth/index.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'perfil' => object(LengthAwarePaginator), 'user' => object(Collection), 'empresas' => object(Collection))) in View.php line 135
at View->getContents() in View.php line 106
at View->renderContents() in View.php line 80
at View->render() in Response.php line 51
at Response->setContent(object(View)) in Response.php line 202
at Response->__construct(object(View)) in Router.php line 1225
at Router->prepareResponse(object(Request), object(View)) in ControllerDispatcher.php line 113
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114
at ControllerDispatcher->callWithinStack(object(PerfilController), object(Route), object(Request), 'create') in ControllerDispatcher.php line 69
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\PerfilController', 'create') in Route.php line 201
at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134
at Route->run(object(Request)) in Router.php line 704
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 706
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 671
modelo:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Empresas extends Model
{
protected $table = 'empresas';
protected $fillable = ['name', 'rfc', 'calle', 'no_int', 'no_exte', 'colonia', 'c_p', 'estado', 'pais', 'municipio'];
public $timestamps = false;
//
}
y modelo del perfil
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Perfil extends Model
{
protected $table = 'perfil';
protected $fillable = ['alta_p_s','alta_kits','alta_garantia','traspasos','kardex','user_id', 'empresa_id'
];
public $timestamps = false;
// Relacion con Category
public function user()
{
return $this->belongsTo('App\User');
}
// Relacion con User
public function empresas()
{
return $this->hasMany('App\Empresas');
}
}