首页 > 解决方案 > 试图获取非对象 laravel7.7 的属性“id”

问题描述

大家好,我在路由中使用前缀进行本地化,当我制作 dd($id); 时,显示和编辑方法的 id 有问题;或 echo 我发现它是前缀“en”或“fr”有人可以帮我吗

在此处输入图像描述

这是路线

Route::group(['prefix'=>'{language?}'], function(){

    Route::get('/', function () { return view('welcome');});
    Route::resource('application', 'ApplicationController');
    Route::resource('appkey', 'AppKeyController');
    Route::get('/export', 'ApplicationController@export')->name('export');
    Route::get('/exportkey', 'AppKeyController@export')->name('exportkey');

});

Route::get('/{any}', function() {
    $locale = app()->getLocale();
    if( !$locale ) {
        $locale = config('app.fallback_locale');
    }
    dd( '/' . $locale . request()->path() );
    return redirect( '/' . $locale . request()->path() );
})->where('any', '.*');
    public function show($id)
        {
            $key = AppKey::find($id);
            return view('pages.keys.show') -> with('key', $key);
        }

        /**
         * Show the form for editing the specified resource.
         *
         * @param  int  $id
         * @return \Illuminate\Http\Response
         */
        public function edit($id)
        {  
            $app = Application::pluck('name', 'app_id');
            $key = AppKey::find($id);
            dd($id);
            return view('pages.keys.edit', compact('app')) -> with('key', $key);

        }

标签: phplaravellocalization

解决方案


推荐阅读