I have following problem with laravel. I created an migration called 2017_07_21_190208_create_spielplans_table.php in phpmyadmin the table is called spielplans. After the migration in the cmd I got a model Spielplan.php in the app folder. Then I created a controller (SpielplanController.php) via cmd which is in the folder app/http/controllers and look like that...
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Spielplan;
class SpielplanController extends Controller
{
public function getSpielplan(){
$spielplans = Spielplan::all();
return view('datenAbfrage')->with('messages', $spielplans);
}
}
After that I created a route in the routes/web.php which looks like this
Route::get('/datenAbfrage', 'SpielplanController@getSpielplan');
And then my view in the view folder datenAbfrage.blade.php ...
@if(count($spielplans) >0)
@foreach($spielplans as $spielplan)
<ul class="list-group">
<li class="list-group items">Name: {{$spielplan->spieltag}}</li>
</ul>
@endforeach
@endif
-> spieltag is one field in the spielplans database!
Now I get an error Undefined variable: spielplans (View: /Applications/XAMPP/xamppfiles/htdocs/Dateneingabe/resources/views/datenAbfrage.blade.php) in line 3
Can anyone tell me what my problem is. For me it is not clear how larval/eloquent make connection the the database table...
I'm new with laravel, but I hope that anyone can give me a solution of my problem
->with('messages', $spielplans);will set$messagesin your view to the contents of$spielplans. What you wanted was->with('spielplans', $spielplans)see here for more info - castis