【问题标题】:Show function in laravel return blank array[]在 laravel 中显示函数返回空白数组 []
【发布时间】:2021-07-07 13:13:51
【问题描述】:

我的代码中有一个名为 Prediction 和 Memeberdetails 的模型。我想在下一页显示特定员工的详细信息,这意味着当用户单击员工编号时,它应该重定向到新页面,并且应该显示该成员的所有详细信息。 当我返回模型 Membersdetails 时,它工作得非常好,同样想为模型预测做这件事,但是当我试图为此返回时,它返回空白数组,不确定我在这方面做错了什么。

这是我的路线

Route::resource('/detail', PredictionController::class);

这是我希望用户重定向并获取员工详细信息的视图

columns: [
                {
                    data: 'EmployeeNumber',
                        name: 'EmployeeNumber',
                    render:function(data, type, row){
                    //console.log(row)}
                    //return "a"}
                    return "<a href='/detail/"+ row.id +"'>" + row.EmployeeNumber+"</a>"}
                },

这是我的控制器:

public function show(Prediction $prediction)
    
        {
            
            $Attrition_correlator = Attrition_correlators::all();
            //return view('admin.members.Detailspage',compact('prediction','Attrition_correlator'));
            return $prediction;
        }

这是我的模型:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Prediction extends Model
{
    use HasFactory;
    protected $fillable = ['Feedback'];
}

我在这方面做错了什么或我缺少相同的代码对其他模型工作正常,但这个模型返回空白......有什么帮助吗?

【问题讨论】:

    标签: laravel eloquent laravel-8


    【解决方案1】:

    尝试将$prediction 更改为$detail

    public function show(Prediction $detail)
    {
                
       return $detail;
    }
    

    它应该匹配路由参数。运行以下命令并查看从资源生成的路由

    php artisan route:list
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-27
      • 1970-01-01
      • 2020-07-04
      • 2015-11-30
      • 1970-01-01
      • 2020-06-26
      • 2021-10-05
      • 2015-08-12
      相关资源
      最近更新 更多