第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

訪問不同頁面上的變量的問題

訪問不同頁面上的變量的問題

PHP
慕的地6264312 2022-12-03 10:25:04
我需要能夠在整個(gè)應(yīng)用程序中(在所有刀片文件中)訪問某些變量。目前我只能在一個(gè)頁面上訪問它們,并且該頁面是在控制器 (profile.show) 中設(shè)置的。我成功地通過 AppServiceProvider.php 中的 view composer 訪問了其中一個(gè)變量,但我無法訪問其他變量。當(dāng)我將它們轉(zhuǎn)儲(chǔ)到其他刀片上時(shí),它顯示未定義的錯(cuò)誤,但 profile_details 工作正常。我需要有關(guān)如何將這些變量($profile、$data、$options、$photos)放入 AppServiceProvider.php composer 以便能夠訪問它們的幫助。任何幫助表示贊賞。這是我的代碼。AppServiceProvider.php<?phpnamespace App\Providers;use App\User;use App\UserProfile;use Illuminate\Support\Facades\Auth;use Illuminate\Support\ServiceProvider;use Illuminate\Database\Schema\Builder; // Import Builder where defaultStringLength method is definedclass AppServiceProvider extends ServiceProvider{    /**     * Register any application services.     *     * @return void     */    public function register()    {    }    /**     * Bootstrap any application services.     *     * @return void     */    public function boot()    {         view()->composer('*', function ($view) {            $view->with('profile_details', Auth::id() ? UserProfile::profileDetails(Auth::id(), Auth::id()) : []);          });        Builder::defaultStringLength(191); // Update defaultStringLength    }}UserProfileController.phpclass UserProfileController extends Controller{    public function showProfile($username, Request $request)    {        $user = $request->user();        $viewer = User::find(Auth::id());        $owner = User::where('username', $username)->first();        if($viewer->id !== $owner->id && !$owner->active){            abort(404);        }        if(!$profileId = User::getIdFromUsername($username)){            abort(404);        }        $profile = UserProfile::profileDetails($profileId, $viewer->id);        $data = UserProfile::getProfileLookingFor(Auth::user()->id);        $options = UserProfile::getProfileLookingForDisplayOptions();        $details = $this->returnDropdowns();        $photo = new Photo();        $photos = $photo->managePhotos();        return view('profile.show', compact('user', 'profile', 'data', 'options', 'details', 'photos'));    }}
查看完整描述

1 回答

?
Cats萌萌

TA貢獻(xiàn)1805條經(jīng)驗(yàn) 獲得超9個(gè)贊

您可以使用View::share訪問所有視圖中的變量:


在 的boot方法中AppServiceProvider執(zhí)行以下操作:


public function boot() {


    $profile_details = Auth::id() ? UserProfile::profileDetails(Auth::id(), Auth::id()) : [];


    View::share('profile_details', $profile_details);


    Builder::defaultStringLength(191); // Update defaultStringLength

}

有關(guān)的文檔View::share


查看完整回答
反對(duì) 回復(fù) 2022-12-03
  • 1 回答
  • 0 關(guān)注
  • 108 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)