将变量传递给视图时出错(laravel 5.3)

I make a notify controller there I made a method as

public function getNotificationsView(){
    $ = UserNotifications::orderBy('id', 'desc')->get();
    return $notifications;
}

now this notifications variable i want to use it in my header.blade.php as i am trying to do it gives an error my header.blade.php

<li class="dropdown dropdown-extended dropdown-notification" id="header_notification_bar">
    <a href="{{ route('user.notification') }}" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true">
        <i class="icon-bell"></i>
        <span class="badge badge-default"> 7 </span>
    </a>
    <ul class="dropdown-menu">
        <li>
            <ul class="dropdown-menu-list scroller" style="height: 250px;" data-handle-color="#637283">
                @foreach($notifications as $users)
                <li>
                    <a href="javascript:;">
                        <span class="time">just now</span>
                        <span class="details">
                            <span class="label label-sm label-icon label-success">
                                <i class="fa fa-plus"></i>
                        </span> {{$users->title}} </span>
                    </a>
                </li>
                @endforeach
            </ul>
        </li>
    </ul>
</li>

Route is as

Route::any('/notification', ['as' => 'user.notification', 'uses' => 'NotificationController@getNotificationsView']);

It gives "Error: undefined variable notifications"

You're not passing any variables to the view. Do this:

public function getNotificationsView()
{
    $notifications = UserNotifications::orderBy('id', 'desc')->get();
    return view('notifications', compact('notifications'));
}

Or:

public function getNotificationsView()
{
    $notifications = UserNotifications::orderBy('id', 'desc')->get();
    return view('notifications', ['notifiactions' => $notifications]);
}

You should add the blade in the return clause.

public function getNotificationsView(){
        $notifications = UserNotifications::orderBy('id', 'desc')->get();
        return View::make('blade name', ['notifications' => $notifications]);
    }

replace this below two line in getNotificationsView()

$data['notifications'] = UserNotifications::orderBy('id', 'desc')->get();
return view('viewname')->withdata($data);

and add below code in view.Blade file:

@foreach($notifications as $users)
 ..... write html code .....
@endforeach