Following is my php code:
<table class="table table-striped">
<tr>
<?php
for ($i=1;$i<=8;$i++)
{
echo "<td>";
echo "<b>Col-".$i."</b><br>";
for ($j=1;$j<=15;$j++)
{
echo "Row-".$j."<br>";
}
echo "</td>";
}
?>
</tr>
</table>
So this basically prints the data values of each row header below them, column-wise that is.I want to implement the same in a Laravel view, wherein data would be passed from the controller to the view.
I tried implementing the same using the below code:
View:
<form action='/display' method="post">
<table style="table-layout: fixed; width:100%;" border=1>
{!! csrf_field() !!}
<thead>
<tr>
@foreach($todo as $todo)
<td>
@foreach($todo1 as $todo1)
<table>
<tr>
<td>
</td>
</tr>
</table>
@endforeach
</td>
@endforeach
</tr>
</thead>
</table>
Controller:
<?php
namespace App\Http\Controllers;
use App\Todo;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
//use Illuminate\Database\MySqlConnection;
class TodoController extends Controller
{
public function index()
{
$todo=DB::table('todos')->select('status')->groupBy('status')->get();
//dd($todo);
$todo1=DB::table('todos')->where('status','todo')->get();
//dd($todo1);
return view ('display',compact('todo1','todo'));
}
}
But I keep getting this error:
ErrorException
Trying to get property of non-object (View: lar4/resources/views/display.blade.php)
Any suggestions on what needs to be done here, I just want the format of the table like the one in the php code that I described at the start.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire