php - Laravel 5 passing database query from controller to view -
i'm new laravel 5 , mvc frameworks in general. having trouble getting results database query , passing blade view. here have controller function ...
public function show(project $project) { $technologies = db::select('select * technologies id = ?', [$project->technology_id]); return view('projects.show', compact('project','technologies')); }
and view ...
@section('content') <h2>{{ $project->name }}</h2> @if ( !technologies() ) no technologies. @else <ul> @foreach( $technologies $technology ) <li><a href="#">{{ $technology->slug }}</a></li> @endforeach </ul> @endif @endsection
thanks help
controller
public function show(project $project) { $technologies = db::table('technologies') ->select('*') ->where('id', $project->technology_id) ->get(); // missing method return view('projects.show', compact('project', 'technologies')); }
view
this not work in view: @if ( !technologies() )
@section('content') <h2>{{ $project->name }}</h2> @if($technologies) <ul> @foreach($technologies $technology) <li><a href="#">{{ $technology->slug }}</a></li> @endforeach </ul> @else <p>no technologies.</p> @endif @stop
also, if you're interested in cleaner way loop through data or show 'no data' warning using blade check out article uses blade's @each https://laravel-news.com/2014/09/laravel-blade/
Comments
Post a Comment