dongzhuang5741
2019-03-18 04:58
浏览 56
已采纳

为什么我找不到Laravel刀片中的数据

This is my error:

Undefined variable: salesdate (View: C:\Users\jingh\blogesources\views\layouts\home.blade.php)

This is my home.blade.php

@extends('layouts.login')

@section('content')
{{ csrf_field() }}

<h1>Laravel</h1>
  @foreach ($salesdate as $key => $value)
      {{ $value->grand_price }}
  @endforeach
@endsection

I already add my model inside

use App\Sales;

This in my controller

public function dateview()
{
    $salesdate = Sales::whereDate('created_at', '2019-03-13')->get();

    return view ('layouts/home', [
      'salesdate' => $salesdate
    ]);
}

This is my route

Route::get('/sales/{id}/dateview', 'SalesController@dateview')->name('sales.dateview')->middleware('auth');
Auth::routes();
Route::get('/', 'HomeController@index')->name('home');

How to fix this issue? Thanks

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douhuo1738 2019-03-18 05:47
    已采纳

    In your routes, you tell it to use the index() method,

    Route::get('/', 'HomeController@index')->name('home');
    

    But in your controller, you have named it dateview(). The route should be

    Route::get('/', 'HomeController@dateview' )->name('home');
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题