一直试图从我的 vew 中获取这些代码的输出,但它给我带来了问题,请我真的很乐意寻求帮助。在我的控制器中<?phpnamespace App\Http\Controllers;use Illuminate\Http\Request;use Illuminate\Support\Facades\Input;use App\leaveType;use App\allLeave;use App\leaveDepartment;class LeavesController extends Controller{ public function getAllLeave() { $data = App\allLeave::find(1)->full_name; return view('leave/allLeave',["data"=>$data]); }}在我的员工模型中<?phpnamespace App;use Illuminate\Database\Eloquent\Model;/** * Class Personnel * @package App */class Employee extends Audit{ public function leave() { return $this->belongsTo('App\allLeave'); }}在所有离开模型<?phpnamespace App;use Illuminate\Database\Eloquent\Model;class allLeave extends Model{ public function empolyee() { return $this->hasMany('App\Employee'); }}在刀片{{$data->employee->full_name}}
3 回答
千万里不及你
TA贡献1784条经验 获得超9个赞
如果我必须做同样的事情,我会这样做
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use App\leaveType;
use App\allLeave;
use App\leaveDepartment;
class LeavesController extends Controller
{
public function getAllLeave()
{
/* No need to use App\allLeave because you already have that used in
top of the project */
$data=allLeave::findorFail(1);
return view('leave.allLeave')->with('data', $data);
}
}
在前端只使用
{{$data->first_name}} //same column as in database table
注意:确保使用 laravel eloquent 模型关系
DIEA
TA贡献1820条经验 获得超2个赞
在你的控制器中应该是这样的:
$data = App\allLeave::find(1)->empolyee();
还有你的刀片:
{{$data->full_name}}
- 3 回答
- 0 关注
- 101 浏览
添加回答
举报
0/150
提交
取消