簡體   English   中英

如何從控制器發送數據到包含/頭刀片文件,但在 Laravel 中返​​回另一個刀片文件

[英]how to send data from controller to include/header blade file but return another blade file in laravel

我想將我的數據從我的控制器發送到我的header.blade.php文件中,但我想返回 laravel 中的另一個視圖,如下所述:-

public function handleProviderCallback()
{
    $user = Socialite::driver('google')->stateless()->user(); 
    $finduser = User::where('google_id', $user->id)->first();

    if($finduser) {
        Auth::login($finduser);
        $google_avatar = $user->getAvatar();
        view('pages.home',['google_avatar', $google_avatar]);  
        return redirect()->route('home',);      
    }
}

通過擴展布局是最干凈的方式。

從文檔:

<!-- Stored in resources/views/layouts/app.blade.php -->

<html>
    <head>
        <title>App Name - @yield('title')</title>
    </head>
    <body>
        @section('sidebar')
            This is the master sidebar.
        @show

        <div class="container">
            @yield('content')
        </div>
    </body>
</html>

孩子:

@extends('layouts.app')

@section('title', 'Page Title')

@section('sidebar')
    @parent

    <p>This is appended to the master sidebar.</p>
@endsection

@section('content')
    <p>This is my body content.</p>
@endsection

通過僅從控制器返回“子”視圖,數據也將在標題中可用。 如果你在@extends聲明中傳遞它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM