Displaying authenticated user data in the view

Asked

Viewed 3,535 times

4

I have a problem that I believe is quite simple... I need to display the username logged in to my views... how do I do that?

this is one of the views

@extends('layouts.template')

@section('body')

<h3>List_Lists</h3>
<p>
    <a href="{{ URL::to('list/create') }}">Adicionar Lista</a> <br />
</p>

<ul style="list-style:none;">
    @foreach($lists as $lista)
        <li class="task">
            <a href="{{ URL::to('list') }}/{{ $lista->id }}">{{ $lista->titulo }}
            ({{ count( $lista->tasks ) }} Tasks)</a> <br />
        </li>
    @endforeach
</ul>
@stop   
  • I suggest changing the title of the question for something that better defines the problem. To help in the search of other people who have the same doubt.

2 answers

8

{{ Auth::user()->nome }}

Or in place of the name property, which you need to use.

  • @Henrique - Add a new question, so we don’t mix the problems, please add besides the Laravel tag, the Lade tag

  • Thanks Flavio ..... and Blz Hernandes.... more not to leave the subject I can not understand I create a Model with relationships, a controller inserting or fetching data in a bd and a View to display the results... but if I want to display the results of Multiple tables from my bd in the same view if I have a Return View::make() returning queries from just one table ?? ex: view Index.Link I show user logadotabela(user), latest news(table news), featured products(table products)..... Obs.: I wish I could understand ... hehe

4

In your View you will already have:

{{ Auth::user()->nome }}

to display the user name Logged in.

You can pass multiple variables to your view:

$produtos  = Produtos::all();
$novidades = Novidades::all();
View::make('index', compact("novidades","produtos") )
  • I was almost doing that. hehehe... made a query , stored in a variable but could not pass to view because it was missing the Compact("var").... vlw Flávio... Today you saved my life the hell you saw... hehhe

Browser other questions tagged

You are not signed in. Login or sign up in order to post.