Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel error : Namespace declaration statement has to be the very first statement or after any declare call in the script

After I pull my project in git, I get this error. It's my 1st time to encounter this error.

The error is:

Namespace declaration statement has to be the very first statement or after any declare call in the script.

my Model

 <?php
 
namespace App\Models;

The version of my Laravel is 5.5.

like image 393
Kenneth Avatar asked Sep 21 '17 04:09

Kenneth


3 Answers

There is an empty space before the <?php tag. Remove it.

<?php

namespace App\Models;
like image 125
Gayan Avatar answered Nov 15 '22 19:11

Gayan


Also check that your IDE create UTF-8 files (with NO BOM) UTF-8 BOM. For example, in phpStorm Settings / Editor / File Encodings -> Create UTF-8 files: with NO BOM

like image 45
ShirleyCC Avatar answered Nov 15 '22 20:11

ShirleyCC


If problem continue you have to remove bom from file via notepad++

like image 2
veyselsahin Avatar answered Nov 15 '22 19:11

veyselsahin