Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 syntax error, unexpected 'extends' (T_EXTENDS)

This is the code in my controller:

class ArticlesController extends Controller {
    public function index()
    {
        $articles = Article::all();
        return view('articles.index',compact('articles'));
    }

}

My App.blade.php

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Title</title>
        <meta charset="UTF-8">
        <meta name=description content="">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <!-- Bootstrap CSS -->
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" media="screen">
    </head>
    <body>
        <div class="container">
            @yield('content')
        </div>

        @yield('footer')
        <!-- jQuery -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <!-- Bootstrap JavaScript -->
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    </body>
</html>

And index.blade.php

<?php

@extends('app')

@section('content')
    <h1>Articles</h1>
@stop

This is the error that I get:

FatalErrorException in 5f3efcdeb3d9812b22b5491d0cba9f22 line 3:
syntax error, unexpected 'extends' (T_EXTENDS)

Please help.


Solution listed below. While the issue is silly, and easy to fix - it's hard to find a straight answer via Google Search. Hence keeping this question.

like image 775
Santosh Achari Avatar asked Jun 03 '15 22:06

Santosh Achari


4 Answers

The <?php ?> Tags are not required in .blade.php files. Remove them and it works.

(The blade syntax need not be in php tags. You can however, include PHP code in tags.)

like image 184
Santosh Achari Avatar answered Nov 07 '22 19:11

Santosh Achari


The <?php ?> tags are not required in your laravel blade file saved with extension .blade.php laravel templating engine automatically parse blade commands from these files.

But if you want to include php code in your blade file which is not part of blade engine commands then you will have to use <?php ?> tags.

like image 41
Akshay Khale Avatar answered Nov 07 '22 20:11

Akshay Khale


I know this is a bit old but the issue was clearly missed.

In your index.blade.php file your missing the closing php tag "?>".

The blade sytanx @extends, @section etc... should be in your html on the outside of any php code block.

like image 2
Aaron Avatar answered Nov 07 '22 21:11

Aaron


When you use @extends, it must be the first piece of code in your blade file.

A blank space or an empty new line before @extends will also throw an error.

like image 1
user2094178 Avatar answered Nov 07 '22 20:11

user2094178