File tree Expand file tree Collapse file tree 3 files changed +23
-3
lines changed Expand file tree Collapse file tree 3 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 6
6
7
7
class Task extends Model
8
8
{
9
- //
9
+ public function getRouteKeyName () {
10
+ return 'name ' ; // 以任务名称作为路由模型绑定查询字段
11
+ }
10
12
}
Original file line number Diff line number Diff line change 2
2
3
3
namespace App \Providers ;
4
4
5
+ use App \Models \Task ;
5
6
use Illuminate \Support \Facades \Route ;
6
7
use Illuminate \Foundation \Support \Providers \RouteServiceProvider as ServiceProvider ;
7
8
@@ -23,7 +24,8 @@ class RouteServiceProvider extends ServiceProvider
23
24
*/
24
25
public function boot ()
25
26
{
26
- //
27
+ // 显式路由模型绑定
28
+ Route::model ('task_model ' , Task::class);
27
29
28
30
parent ::boot ();
29
31
}
Original file line number Diff line number Diff line change 95
95
Route::get ('task/create ' , 'TaskController@create ' );
96
96
Route::post ('task ' , 'TaskController@store ' );
97
97
98
- Route::resource ('post ' , 'PostController ' );
98
+ Route::resource ('post ' , 'PostController ' );
99
+
100
+ Route::get ('task/{id} ' , function ($ id ) {
101
+ $ task = \App \Models \Task::findOrFail ($ id );
102
+ });
103
+
104
+ Route::get ('task/{task} ' , function (\App \Models \Task $ task ) {
105
+ dd ($ task );
106
+ });
107
+
108
+ Route::get ('task/model/{task_model} ' , function (\App \Models \Task $ task ) {
109
+ dd ($ task );
110
+ });
111
+
112
+ Route::fallback (function () {
113
+ return '我是最后的屏障 ' ;
114
+ });
You can’t perform that action at this time.
0 commit comments