Kehinde Adeoya
Kehinde Adeoya

Reputation: 31

syntax error, unexpected 'in' (T_STRING) Laravel 5

Controller class for Authors

public $restful=true;
    public function index()
    {
        $author = Author::all();
        return \View::make('authors.index', ['authors' => $author]);
    }

Model class for authors

class Author extends Model
{
    protected $table = 'authors';
}

View file for Author

@extends('layouts.default')
    @section('content')
        <h1>THIS IS AUTHOR'S PAGE</h1>

        <ul>
            @foreach($authors in $author)
                <li>{{ $author->name }}</li>
            @endforeach
        </ul>
    @endsection

Display page for authors

<!DOCTYPE html>
<HTML>
    <HEAD><TITLE>Testing</TITLE></HEAD>
    <BODY>
        @yield('content')
    </BODY>
</HTML>

Error response that I'm getting.

FatalErrorException in 6d4e39a843ef4ce0421f063e7b907f68 line 5:
syntax error, unexpected 'in' (T_STRING)

I'm unable to know exactly where this error is coming from since it returns a string code that is I'm unable to interpret.What can i do . Thanks.

Upvotes: 0

Views: 2573

Answers (2)

Saad
Saad

Reputation: 1221

I think you should replace

@foreach($authors in $author)

with

@foreach($author as $authors)

Upvotes: 1

Richard
Richard

Reputation: 2815

I think it should be as instead of in (in do not make sense in this order):

@foreach($authors as $author)
    <li>{{ $author->name }}</li>
@endforeach

Upvotes: 2

Related Questions