I am using laravel and I have a problem that I cannot find errors even though I have searched many and tried many different uses but I still get an Undefined variable: post error (View: C: \ xampp \ htdocs \ blog-news \ resources \ views \ layouts \ news.blade.php) Please help me, thanks !!
This is my controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Category;
use App\Post;
class DataController extends Controller
{
// insert data
public function insertData()
{
$post = Post::all();
return view('layout.news',['post',$post]);
}
}
And here is my code in news.blade.php:
@foreach($post as $p)
<h1>{{ $p -> name}}</h1>
@endforeach
and this route of me: Route::get('/news','DataController@insertData');