0

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');

job
  • 1
  • Typo: `return view('layout.news',['post',$post]);` should be `return view('layout.news',['post' => $post]);` – Qirel Jul 03 '20 at 07:12
  • You should also be using laravel naming standards, as that will likely help you in the future (in terms of controller method and route names). – Qirel Jul 03 '20 at 07:13
  • I tried and made your way but I still get the Undefined variable error. ```return view('layout.news',['post'=>$post]);``` – job Jul 03 '20 at 07:21

0 Answers0