Getting value from database in blade template in laravel 5.4

Here I want to get value from database. I am using this in layout and I don't want to use controller for getting value. It does not show anything. How can I fix it? Thank in advance

info.blade.php

{{$data = \App\visitor::where('flag',1)->get()}}

    @foreach ($data as $val)
       Name  {{ $val->v_name }} <br>
       Mobile  {{ $val->v_mobile }}
     @endforeach

Upvotes: 1

Views: 1802

Answers (1)

Anar Bayramov
Anar Bayramov

Reputation: 11584

Even though its not a good idea to not use controller you can do like

@php
    $data = \App\visitor::where('flag',1)->get()
@endphp 

Upvotes: 1

Related Questions