using laravel 5.5 and get error to create my controller? - laravel

I am using laravel 5.5 and I get an error when I create my controller.
$ php artisan make:controller MyDatatablesController
I want to create new controller but I get this error:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW)

Your command is perfect their is some error in your project check your recent changes in your project

You're having an error on your own code. Probably it's a code not always executed. Try executing the command in verbose mode to have more information about the error
php artisan make:controller MyDatatablesController -vvv

Related

Laravel Tinker error with SQLite database

Starting from a fresh project:
laravel new new-project
cd new-project
touch storage/database/database.sqlite
Then at .env
DB_CONNECTION=sqlite
DB_DATABASE=storage/database/database.sqlite
DB_FOREIGN_KEYS=true
The migration succeed...
php artisan migrate
php artisan tinker
>>>App\User::all()
But when I try to get all users it returns the following error:
PHP Fatal error: Class 'App/User' not found in Psy Shell code on line 1
What I could be missing?
Recently I reinstalled Laravel...
And I didn't realized I was using version Laravel 8
the models are at /app/Models
So the right command would be:
>>>App\Models\User::all()
i think it has something to do with the namespace alias. Try without the App/
Users::all();

Error while migrating from Laravel tinker console (sqlite)

Consider
laravel new bug
Then adding in .env
DB_CONNECTION=sqlite
DB_DATABASE=/home/me/Code/bug/storage/database.sqlite
creating database
touch /home/me/Code/bug/storage/database.sqlite
migrating
php artisan migrate && php artisan migrate:fresh
Now trying to migrate programmatically in tinker
php artisan tinker
>> Artisan::call('migrate');
First time resulting in => 0 (as expected ?) But second time:
>>> Artisan::call('migrate:fresh')
Illuminate\Database\QueryException with message 'SQLSTATE[HY000]:
General error: 17 database schema has changed (SQL: select * from
sqlite_master where type = 'table' and name = migrations)'
Artisan::call('migrate')
Third time:
Symfony\Component\Console\Exception\CommandNotFoundException with
message 'There are no commands defined in the "migrate" namespace.'
Any ideas whats going on here? Can you reproduce?
Update using postgres. The second time running Artisan::call('migrate:fresh') I get:
Symfony\Component\Console\Exception\CommandNotFoundException with
message 'There are no commands defined in the "migrate" namespace.'
UPDATE 2: Issue filed here: https://github.com/laravel/framework/issues/22997
https://github.com/laravel/tinker/issues/37
I don't think if this is a laravel bug, but I found your problem:
Calling a non existing command like Artisan::call('migrate:fresh') will crash. The reason is a typo: tinker does not accept fresh, only refresh. Calling the command via tinker will empty the sqllite file so you can't execute any commands until you migrate without tinker.
Here are my steps:
php artisan migrate # sqllite file is filled with content
php artisan tinker
> Artisan:call('refresh')
> Artisan::call('fresh') # now the sqllite file is empty
> Artisan::call('migrate') # will crash
php artisan migrate
> Artisan::('refresh') # works
so I think it's a tinker bug, not a laravel one. Tinker is doing some kind of snapshot (If you change a Model you have to restart tinker to call it there), maybe the error handling is not implemented is the best way to catch all errors.

Laravel 5: How to get config value in artisan console command

I get config values in Laravel like this:
$value = config('app.name');
If I try the same in a method, which is called from an artisan command, then I get the following error message:
[ErrorException] Trying to get property of non-object
Is it possible to get config values from an artisan console command?
I have found a solution for Laravel 4, but there is no such method in Laravel 5.
config() helper use application instance and it can be not available in the console. Try this solution Config::get('app.name')

how to solve this exception in laravel ? Symfony\Component\Debug\Exception\FatalThrowableError

I run this command to create model.
php artisan make:model BaseModel
but issue this exception
[Symfony\Component\Debug\Exception\FatalThrowableError]
Parse error: syntax error, unexpected '<<' (T_SL), expecting end of file
may i know how to handle this issue.
There is a syntax error in your file. Check your routes, blades and controllers and search "<<". I think this is in your blade file.
<<input..>
<<div..>
etc..

making model and migration with a single command in laravel 5.2

I've tried this artisan command as I followed a tutorial
php artisan make:model Foo -m
but I get this error:
exception 'RuntimeException' with message 'The "-m" option does not exist.'
why It's not recognizing that?
If It's a wrong way to do It , what the right one?
In short, this is how you do it.
C:\xampp\htdocs\lms>php artisan make:model Test -m
Model created successfully.
Created Migration: 2016_08_29_160434_create_tests_table
It must work. If that does not, do.
C:\xampp\htdocs\lms>composer install.
and that should work.

Resources