TransWikia.com

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

Stack Overflow Asked on November 10, 2021

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 AppModels;

The version of my Laravel is 5.5.

6 Answers

You may have bad file encoding. In my case, I just use Notepad++ and converted the file to UTF-8 (while it was supposed to be already in UT8)

Answered by Handsome Nerd on November 10, 2021

i can change name of your Controller and create a new Controller. Then copy your information of your first Controller to second Controller. This solution its ok for me

Answered by xavifar on November 10, 2021

In some cases, it may be that you're looking at the wrong. Especially in Laravel/Laravel testing, if you move, copy or rename a file. Possibilities are it could be pointing to the old file.

Answered by Lekia on November 10, 2021

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

Answered by ShirleyCC on November 10, 2021

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

Answered by veyselsahin on November 10, 2021

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

<?php

namespace AppModels;

Answered by Gayan on November 10, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP