-3

This is my services.blade.php file. I am getting error at services.blade.php file. after the creation of the array in services.blade.php file i am getting such error. plz help me

@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

this is the page controller.php. i am getting error in this file. before creating array, everything working well after the array i am getting syntax error, i checked everything but unable to find the problem

<?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);
           }
        }

this is the web.php file

<?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;
});

1 Answers1

-1

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

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

It may be that ->with() has trouble with Passing multidimensional arrays to blade using controller "Maybe" :)

Cameron
  • 532
  • 3
  • 9