【问题标题】:syntax error, unexpected ')', expecting '[' [duplicate]语法错误,意外')',期待'[' [重复]
【发布时间】:2020-07-04 20:12:34
【问题描述】:

这是我的 services.blade.php 文件。我在 services.blade.php 文件中遇到错误。在 services.blade.php 文件中创建数组后,我收到了这样的错误。请帮帮我

@extends('layouts.app')


    @section('content')
    
        <h1> {{ $title }} </h1>
        <p> This is the service page </p>
    
        @if(count($services) > 0)
            <ul>
                @foreach($services as service)
                    <li> {{ $service }} </li>
                @endforeach    
            </ul>
        @endif
    
    @endsection

这是页面controller.php。我在这个文件中收到错误。在创建数组之前,在数组之后一切正常我收到语法错误,我检查了所有内容但找不到问题

<?php
        
        namespace App\Http\Controllers;
        
        use Illuminate\Http\Request;
        
        class PagesController extends Controller
        {
           public function index(){
            $title = "Welcome to the new laravel project!";
            // return view('pages.index', compact('title'));
            return view('pages.index')->with("title", $title);
           }
        
           public function about(){
            $title = "about us";
            return view('pages.about')->with("title", $title);
           }
        
           public function services(){
            $data = array(
                'title' => "Services",
                'services'=> ['web design', 'programming', 'SEO']
            );
            return view('pages.services')->with($data);
           }
        }

这是 web.php 文件

<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

// Route::get('/', function () {
//     return view('welcome');
// });

Route::get('/', 'PagesController@index');
Route::get('/about', 'PagesController@about');
Route::get('/services', 'PagesController@services');


// Route::get('/hello', function () {
//     return "Hello world";
// });

// Route::get('/about', function () {
//     return view('pages.about');
// });

Route::get('/user/{id}', function ($id) {
    return "this is the user". $id;
});

【问题讨论】:

  • 可以分享 layouts.app 吗?只是为了确保没有任何东西导致它

标签: php laravel oop


【解决方案1】:

试试return view('pages.services',compact('data'));

  @foreach($data['services'] as $service)
          <li> {{ $service }} </li>
        @endforeach

可能是 ->with() 在使用控制器将多维数组传递给刀片时遇到问题 “也许”:)

【讨论】:

  • 不,它不工作
  • 'services'怎么样=> array('web design', 'programming', 'SEO')
  • 亲爱的你们都没有注意到我忘记在服务中使用 $ 符号;这就是我收到此错误的原因
猜你喜欢
  • 2013-06-28
  • 2017-09-12
  • 1970-01-01
  • 2013-09-22
  • 2019-12-06
  • 2013-11-15
相关资源
最近更新 更多