【发布时间】:2019-07-26 11:15:48
【问题描述】:
我试图通过使用依赖注入传递 slug 来获取该行,但 $variable 没有返回任何内容。
控制器方法
public function projectDetails(Project $project_name)
{
dd($project_name);
}
型号
namespace App\Modules\manufacturer\Models;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
protected $table = 'projects';
protected $fillable = ['id', 'name'];
public $timestamps = false;
}
路线
Route::get('manufacturer-project-details/{project_name?}',
'ProjectController@projectDetails');
结果
Project {#1047 ▼
#table: "projects"
#fillable: array:1 [▼
0 => "id"
]
+timestamps: false
#connection: null
#primaryKey: "id"
#perPage: 15
+incrementing: true
#attributes: []
#original: []
#guarded: array:1 [▼
0 => "*"
]
#dates: []
#dateFormat: null
#observables: []
+exists: false
+wasRecentlyCreated: false
}
但是,当我dd($project_details) 时,应该返回一行包含项目名称。
【问题讨论】:
标签: laravel dependency-injection