Database output and laravel blade template display

I work with Laravel framework 4.2.0, its really interesting to work with this structure, but I'm stuck somewhere.

I am trying to output data as a blade from my database table.

I was successfully able to use the query building function to query my database table and output data using this method.

My controller

public function index()
{
    $records = DB::table('record')->get();
    foreach ($records as $record)
    {
        echo ($record->message);
    }
}

and then on my route, which I am viewing using

Route::get('records', 'RecordsController@index');

Now I am trying to transfer this data received from the query designer to my blade like this

public function index()
{
    $records = DB::table('record')->get();
    return View::make('mine')->with('name', '$records');
}

kind of my blade

@extends('layouts.main')
@section('title', 'testing for data')
@section('content')
<div align="center">
    {{name}}    
</div>
@endsection

And I keep getting the whoops error page, I have no idea why this is not working, maybe someone will ask me through

Greetings

+4
1

Laravel 5.2. , .

public function index()
{
$records = DB::table('record')->get();
return view ('Path to your blade template')->with('records',$records); 
}

@foreach ($records as $rec)

        {{ $rec->message }} //here Code is your JSON object name.
@endforeach

.

Route::get('records', 'RecordsController@index');

. . ( ).

+1

Source: https://habr.com/ru/post/1648139/


All Articles