这行得通,但有一个问题——{two}你可以在里面写任何你想要的东西,而且不会出错。仅当在表中未找到指定的 from404时才会出现错误。这是问题的症结所在。id{three}
路线
Route::get('one/{two}/{three}', 'MyController@show')->name('three.show');
Route::get('one/{two}/{three}/edit', 'MyController@edit')->name('three.edit');
控制器
class MyController extends Controller
{
// ...
public function edit($two, $three)
{
$variable = ThirdModel::findOrFail($three);
return view('three.edit', compact('variable'));
}
// ...
}
模型与路线相关{two}并且{three}有关系。ThirdModel::findOrFail($three)之前检查id链接表中是否存在会很棒TwoModel。这可以以某种方式实现吗?
模型
class ThirdModel extends Model
{
// ...
public function MyMethod()
{
return $this->belongsTo('App\TwoModel');
}
// ...
}
如果表之间有连接,那么还有一个列(外键)用于连接它们。在两列上进行选择。