have now tried in 2 days to show the tables from the database (service_types)
With now luck, im new to laravel but i have manage to fix mulltiple problems, but this is giving me a headache.
in the index i have this code:
<h3 class="elementor-heading-title elementor-size-default">{{ trans('index.header_3') }}</h3>
<div class="col-md-12 text-center" style="width: 100% !important">
@foreach($service_type as $index => $service)
<div class="col-md-3" style="margin-left: 00px; margin-right: 00px width: 30%">
@if($service->image)
<img src="{{$service->image}}" style="height: 50px" >
@else
N/A
@endif<br>{{ $service->name }}
</div>
@endforeach
</div>
</div>
but nothing is shown.
Please help.
UPPDATE.
I create one ServiceTypeController.php and add it in the controller folder.
i add this code:
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
use DB;
use AppHttpRequests;
use AppServiceType;
use AppHttpControllersController;
class ServiceTypeController extends Controller {
public function index(){
$service_type = DB::select('select * from service_type');
return view('index',['service_type'=>$service_type]);
}
}
And in the web.php in routes:
Route::get('/','ServiceTypeController@index');
Still dont get any data on the page 🙁
3
Answers
in PHP and many other languages, if array you are trying to loop over is empty, it will not do anything which might be what is happening in your code.
Try to debug your code by putting
just before
@foreach
loop. Once php reachesdd()
function, it will stop executing code and display content of that variable on screen.Use this when rotating the page in the Controller.
You can also use commas to send more data to the view.
Example:
In your ServiceTypeController in the index function
do this: