How to overcome on "Undefined variable" error in laravel? -


i using laravel 5.4 xampp server. working on basic crud operations learn laravel. getting "undefined variable error" on crud operation perform me. code works fine. after click on submit data goes db. error. how overcome error?

home.blade.php:

 @foreach ($companies $company)     <a href="{{ url('dashboard') }}">{{ $company->com_name }}</a><br>  @endforeach 

homecontroller.php:

public function index() {     $companies = db::select('select * company');     return view('home',compact('companies', 'company')); } 

routes/web.php:

route::get('view-company','homecontroller@index'); 

use illuminate\support\facades\view;  public function index()     {  $companies = db::table('company')->select('col1', 'col2')->get();         return view::make('home')->with('companied', $companies);      } 

you not getting thing in $companies object, need define table , get(). way laravel collections. , not use * , try avoid it, select columns needed.

i hope may help.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -