- Пожалуйста, помогите, я не могу получить данные в моем представлении, я получаю эту ошибку: Facade \ Ignition \ Exceptions \ ViewException Неопределенная переменная: post (View: C: \ xampp \ htdocs \ GoHelp \ resources \ views \ posts \ index.blade. php): post я перепробовал почти все возможное.
..... это мой контроллер ......
public function index()
{
$posts = Post::orderBy('created_at', 'DESC')->paginate(10);
$users = User::all();
return view('posts.index',compact('posts', 'users'));
}
....... это мой index.blade. php ...... ..
@section('content')
@if($post->count()>0)
@foreach ($post as $posts )
<div class="container">
<h2></h2>
<div class="panel-heading">Request No:{{ $posts->id }} </div>
<h3>
<a href=" /posts/{{ $posts->id }} "><text>Pick up poin : </text>
{{ $posts->pick_up}}
</a>
</h3>
<div class="panel-body">
<h3>Drop off : {{ $posts->drop_off}}
</h3></div>
<div class="panel-body">
<h3>Date : {{ $posts->date}}
</h3></div>
<div class="panel-body">
<h3>Time : {{ $posts->time}}
</h3></div>
</div>
</div>
@endforeach
{{ $post->links() }}
@else
<div class="alert alert-info"
<strong>Ops</strong> No Posts
</div>
@endif
}}
@section('css')
<link href="/css/style.css" rel="stylesheet">
@stop
@section('javascript')
<script src="{{ ('js/app.js') }}"></script>
@stop
@endsection
.......... маршруты ........
Auth::routes();
Route::get('/', 'PagesController@home');
Route::get('/about', 'PagesController@about');
Route::get('/contact', 'PagesController@contact');
Route::resource('/posts','postsController');
Route::get('posts','postsController@index');
Route::get('/home', 'HomeController@index')->name('home');
Route::resource('/user','UserController');
Route::get('/donate', function(){
return view('pages.Donate');
});
Route::get('/BecomeDriver', function(){
return view('pages.BecomeDriver');
});
Route::get('/admin/Dashboard', function(){
return view('admin.Dashboard');
});
Route::get('/General_Login_Page', function(){
return view('General_Login_Page');
});
Route::get('/home', 'HomeController@index');
// admin routes
Route::prefix('admin')->group(function () {
// Dashboard route
Route::get('/', 'AdminController@index')->name('admin.dashboard');
// Driver Routes
Route::prefix('driver')->group(function () {
// Dashboard route
Route::get('/', 'DriverController@index')->name('driver.dashboard');
......... модель ......
class Post extends Model
{
public function user()
{
return $this->belongsTo('app\User');
}
public function driver()
{
return $this->hasMany('App\Post');
}
}
.............. таблица миграции (creat_posts_table) ......
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->text('pick_up');
$table->text('drop_off');
$table->date('date');
$table->time('time');
$table->timestamps();
});
}