【问题标题】:I have a Laravel error and I can't find anything in this code我有一个 Laravel 错误,我在这段代码中找不到任何东西
【发布时间】:2021-03-12 19:17:26
【问题描述】:

我使用的是 Laravel 5.7,我在这段代码中遇到了错误。

CustomersController.php

<?php

use App\Customers;
use Illuminate\Http\Request;

class CustomersController extends Controller
{
   public function list() 
   {
      $customers = Customer::all();
      return view('internals.costumers.blade.php',[
          'customers' => $customers
      ]);
   }
}

internals.costumers.blade.php

@extends('layout')

   @section('content')
      <h1>This is Customers</h1>
      <ul>
         @foreach ($customers as $customer)
           <li>{{ $customer->name }}</li>
         @endforeach
     </ul>
   @endsection

【问题讨论】:

  • 您收到的错误信息是什么?
  • 你应该告诉你遇到了什么错误并尝试从视图名称中删除 .blade.php view('internals.costumers.blade.php',[ 'customers' =&gt; $customers, ]);
  • internals.costumers.blade.php 拼写错误吗?我想知道是不是应该是internals.customers.blade.php

标签: laravel laravel-5.7


【解决方案1】:

请在控制器和视图助手中定义命名空间,只传递刀片文件的名称,而不是扩展名:.blade.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多