Я хочу сделать следующий запрос с Eloquent:
$nota=DB::table('notas')
->join('users', 'users.id', '=', 'notas.id_user')
->select('notas.id','notas.nombre', 'notas.descripcion', 'users.name AS user_name', 'users.email')
->first();
Я пытаюсь установить отношение в моделях и называется так, в моем контроллере:
public function show($id)
{
$nota = Nota::with(['user','nota'])->first();
print_r($nota);
return view("notas.detalle", compact("nota"));
}
Ноя получаю следующую ошибку:
Illuminate \ Database \ Eloquent \ RelationNotFoundException Вызов неопределенного отношения [nota] для модели [App \ Nota].
Мои модели выглядят так: Nota.php:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Nota extends Model
{
public function user()
{
return $this->belongsTo('App\User');
}
}
User.php:
<?php
namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use Notifiable;
public function notas()
{
return $this->hasMany('App\Nota');
}
}