Migration error on timestamp change field - laravel-5

In laravel 5.7/mysql 5 app I want to set default value to timestamp field(it was not set on creation):
$table->timestamp('created_at')->useCurrent()->change();
But I got error :
Unknown column type "timestamp" requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database introspection then you might have forgotten to register all database types for a Doctrine Type. Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMappedDatabaseTypes(). If the type name is empty you might have a problem with the cache or forgot some mapping information.
at /mnt/_work_sdb8/wwwroot/lar/BoxBooking2/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:267
263| * #return \Doctrine\DBAL\DBALException
264| */
265| public static function unknownColumnType($name)
266| {
> 267| return new self('Unknown column type "' . $name . '" requested. Any Doctrine type that you use has ' .
268| 'to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the ' .
269| 'known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database ' .
270| 'introspection then you might have forgotten to register all database types for a Doctrine Type. Use ' .
271| 'AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement ' .
Usually I do not any problem with timestamp fields and I suppose that method ->change raised this problem.
How to fix it ?
MODIFIED BLOCK # 1 :
I have it istalled
my composer.json :
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.1.3",
"doctrine/dbal": "^2.9",
"fideloper/proxy": "^4.0",
"laravel/framework": "5.7.*",
"laravel/tinker": "^1.0",
"marktopper/doctrine-dbal-timestamp-type": "^1.0",
"mews/purifier": "^2.1",
"proengsoft/laravel-jsvalidation": ">2.2.0",
"yajra/laravel-datatables-oracle": "~8.0"
},
"require-dev": {
"beyondcode/laravel-dump-server": "^1.0",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^2.0",
"phpunit/phpunit": "^7.0"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
],
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
]
}
}
Googling I found that I need also to install marktopper/doctrine-dbal-timestamp-type
https://github.com/art-institute-of-chicago/data-aggregator/commit/581f4f318468681c71c62103280daedc67bbe118
I installed it and I do not have error running migration, but created_at default timestamp is NOT defined, so added new row has null in created_at.
$ php artisan --version
Laravel Framework 5.7.21
$ node -v
v10.15.0
$ npm -v
6.5.0
Thanks!

The documentation states that you can't change / modify the timestamp column types.
Only the following column types can be "changed": bigInteger, binary, boolean, date, dateTime, dateTimeTz, decimal, integer, json, longText, mediumText, smallInteger, string, text, time, unsignedBigInteger, unsignedInteger and unsignedSmallInteger.
You best bet is to use a raw sql query to update the column with something like:
DB::statement('ALTER TABLE `table_name` CHANGE `column_name` `column_name` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP;');

Related

Migration 6 to 7 Laravel Error Parse error: syntax error, unexpected '=' in \vendor\symfony\string\Resources\functions.php on line 34

I'm having this error when migrating a project from laravel 6 to 7 does anyone have an idea how I can solve it.
I've already tried to delete the vendor file and redo the installation from 0 with composer install but I still get the same error. I really don't know what's going on.
Thanks in advance.
Any help is welcome.
Parse error: syntax error, unexpected '=' in C:\projetos\curso\vendor\symfony\string\Resources\functions.php on line 34
PHP Parse error: syntax error, unexpected '=' in C:\projetos\curso\vendor\symfony\string\Resources\functions.php on line 34
My Composer .json
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.2",
"fideloper/proxy": "^4.0",
"guzzlehttp/guzzle": "^6.3",
"laravel/framework": "^7.0",
"laravel/horizon": "^4.0",
"laravel/tinker": "^2.0",
"psr/log": "^1.1.4",
"stripe/stripe-php": "^8.10"
},
"require-dev": {
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^4.1",
"phpunit/phpunit": "^8.5"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"files": [
"app/helpers.php"
],
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
],
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
]
}
}
functions.php --->
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien#symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\String;
if (!\function_exists(u::class)) {
function u(?string $string = ''): UnicodeString
{
return new UnicodeString($string ?? '');
}
}
if (!\function_exists(b::class)) {
function b(?string $string = ''): ByteString
{
return new ByteString($string ?? '');
}
}
if (!\function_exists(s::class)) {
/**
* #return UnicodeString|ByteString
*/
function s(?string $string = ''): AbstractString
{
$string ??= ''; <---Line 34
return preg_match('//u', $string) ? new UnicodeString($string) : new ByteString($string);
}
}
The line 34 error in vendor\symfony\string\Resources\functions.php
$string ??= '';
This is a Null Coalescing Assignment Operator - https://wiki.php.net/rfc/null_coalesce_equal_operator#:~:text=coalescing%20operator%20being%20a%20comparison,not%20null%2C%20nothing%20is%20made.
As stated in the link above this has been implemented in PHP 7.4. You will need to update your PHP version to 7.4

ErrorException When Registering with Laravel 8 Jetstream

I started a project on Laravel 7 just before the launch of Laravel 8, I am still learning this framework, so I updated to that version using this steps, and I am aware of this new scaffolding library call Jetstream that I installed with these steps:
composer require laravel/jetstream
php artisan jetstream:install livewire --teams
npm install && npm run dev
php artisan migrate
After working on my views and models I am proceeding to implement sessions functionalities, but when I tried to register with the project at localhost:8000/register, and having my data validated I get this error
Trying to get property 'id' of non-object (View: \path-to\my-project\resources\views\navigation-dropdown.blade.php) (View: \path-to\my-project\resources\views\navigation-dropdown.blade.php) (View: \path-to\my-project\resources\views\navigation-dropdown.blade.php)
http://localhost:8000/dashboard
This is the section of view that is throwing the exception
navigation-dropdown.blade.php line 169 this is the vanilla file
<!-- Team Settings -->
<x-jet-responsive-nav-link href="{{ route('teams.show', Auth::user()->currentTeam->id) }}" :active="request()->routeIs('teams.show')">
{{ __('Team Settings') }}
</x-jet-responsive-nav-link>
The data introduced in the register form gets stored in the database, but the error happens
I checked this other question Laravel Jetstream + Livewire + Teams FeatureTest problems when authenticate but it seems that answer apply to a different context since it is dealing with tests, no the vanilla register functions.
This is my current composer.json
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.3.0",
"fideloper/proxy": "^4.2",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.0",
"laravel/jetstream": "^1.0",
"laravel/sanctum": "^2.6",
"laravel/tinker": "^2.0",
"livewire/livewire": "^2.0"
},
"require-dev": {
"facade/ignition": "^2.3.6",
"fzaninotto/faker": "^1.9.1",
"mockery/mockery": "^1.3.1",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^8.5"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
],
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
]
}
}
I tried installing to test a fresh Laravel project with Jetstream, and this worked as it should, that let me confused as to what happened with my current project.
In the end, what worked for me was create a new fresh project with jetstream, then in my original project deleted the vendor and node_modules folder then copying the files of the new fresh project unto my original project and now it works as expected
Answer added on behalf of OP.
The user was not created with a team assigned, see users table and column current_team_id is null.
The navigation-menu.blade.php checks only for TeamFeatures but not if a team is really assigned.
#if (Laravel\Jetstream\Jetstream::hasTeamFeatures())
#if (Laravel\Jetstream\Jetstream::hasTeamFeatures() && Auth::user()->current_team_id)
For details here is the issue trying to get property of non-object

Upgrade Laravel project from 5.5 to latest version 8

I want to Upgrade my Laravel project from (5.5 to 8) what I will do for that.
I didn't found any documents to upgrade from 5.5 to 8 just upgrade from 5.5 to 5.6 or from 7 to 8 maybe must upgrade the project step by step from 5.5 to 5.6 the from 5.6 to 5.7 then .... nutil 8
Thanks
composer.json(Laravel 5.5):
{
"name": "HomFolio",
"description": "Smart Property Investing",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=7.0.0",
"ext-json": "*",
"barryvdh/laravel-dompdf": "^0.8.1",
"barryvdh/laravel-translation-manager": "dev-master",
"fideloper/proxy": "~3.3",
"intervention/image": "^2.4",
"joedixon/laravel-translation": "^1.1",
"laravel/framework": "5.5.*",
"laravel/tinker": "~1.0",
"stripe/stripe-php": "^4.7",
"zizaco/entrust": "dev-master"
},
"require-dev": {
"filp/whoops": "~2.0",
"fzaninotto/faker": "~1.4",
"mockery/mockery": "~1.0",
"phpunit/phpunit": "~6.0",
"xethron/migrations-generator": "^2.0"
},
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"dont-discover": [
]
}
},
"scripts": {
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
}
}
composer.json (Laravel 8):
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.2.5",
"fideloper/proxy": "^4.2",
"fruitcake/laravel-cors": "^1.0",
"guzzlehttp/guzzle": "^6.3",
"laravel/framework": "^7.0",
"laravel/tinker": "^2.0"
},
"require-dev": {
"facade/ignition": "^2.0",
"fzaninotto/faker": "^1.9.1",
"mockery/mockery": "^1.3.1",
"nunomaduro/collision": "^4.1",
"phpunit/phpunit": "^8.5"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
],
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
]
}
}
Looks like upgrades are sequential. As of today, I have a laravel 5.7 project that I have to upgrade to Laravel 8 and this looks like the sequence I need to take.
Even when you opt for the highly recommended Laravel Shift, you have to pay for each upgrade as indicated in the picture below.
.
If you have budget, laravel shift looks like a quick and easy way to go through the upgrade(s)
You have to follow the steps given below:
Copy the your current composer.json file.
Now go here https://github.com/laravel-shift/laravel-8.x/blob/master/composer.json and copy composer.json file and replace with your existing composer.json file.
Again go to https://github.com/laravel-shift/laravel-8.x/blob/master/app/Exceptions/Handler.php and copy the Handler.php file and go to app/exceptions/Handler.php replace Handler.php with your existing file.
Run the command composer update.
Check your old or your copied composer.json file and if packages have been added to it then you can add packages through this command composer require <package name>.
Now, again run composer update command.
You going to have to upgrade iteratively I'm afraid.
If you have the budget, you can use a service like Laravel Shift
to automate the upgrade.
Adding to some missing steps to #Krina Mangukiya
/bootstrap/environment.php :
$dotenv = Dotenv\Dotenv::createImmutable(DIR.'/..');
$dotenv->load();
The report and render methods of your application's
App\Exceptions\Handler class should accept instances of the Throwable
interface instead of Exception instances:
use Throwable;
public function report(Throwable $exception); public function
render($request, Throwable $exception);
This answers have taken from stackoverflow only but would be go to have all issue answers in one place.

Laravel 5.8 to 6.x upgrade error - Declaration of App\Exceptions\Handler::renderHttpException

I have recently upgraded Laravel in the project from 5.8.* to 6.x version.
Now when I try running command composer dump-autoload -o, I get this error:
Declaration of App\Exceptions\Handler::renderHttpException(Symfony\Component\HttpKernel\Exception\HttpException $e)
should be compatible with Illuminate\Foundation\Exceptions\Handler::renderHttpException(Symfony\Component\HttpKern
el\Exception\HttpExceptionInterface $e)
Below is the composer.json set in the project, when I upgraded Laravel from 5.7.* to 5.8.*, then also I got this same error as above, but I upgraded further hoping that would fix the issue:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"repositories": [
{
"type": "composer",
"url": "https://packages.[company_api].com"
}
],
"require": {
"php": ">=7.1.3",
"basemkhirat/elasticsearch": "^1.3",
"botman/botman": "^2.5",
"botman/driver-web": "^1.5",
"deployer/deployer": "^6.0",
"fideloper/proxy": "^4.0",
"guzzlehttp/guzzle": "^6.3",
"jenssegers/agent": "^2.6",
"jimmiw/php-time-ago": "^2.0",
"laravel/framework": "^6.0",
"laravel/scout": "^8.0",
"laravel/tinker": "~1.0",
"[company_name]/wordpressblogapi": "1.4.*"
},
"require-dev": {
"filp/whoops": "~2.0",
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~7.0"
},
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/"
},
"files": [
"helpers/helpers.php"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
}
}
I have referred the docs and it doesn't specifically say about any Exception or Handler.php file changes, so anyone do suggest how to resolve this...
This is a 5.7 to 5.8 upgrade issue, as you point out when the problem started. The signature of that method changed:
"The renderHttpException method signature of the Illuminate\Foundation\Exceptions\Handler class has changed. If you are overriding this method in your exception handler, you should update the method signature to match its parent:"
/**
* Render the given HttpException.
*
* #param \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface $e
* #return \Symfony\Component\HttpFoundation\Response
*/
protected function renderHttpException(HttpExceptionInterface $e);
Laravel 5.8 Docs - Upgrade Guide - Exception Handling

Package not found from vcs repo

I have forked a repo and created a branch called 3.0 that I would like to install to my project to test (not a longterm fork. I want to create a pull request after testing). I have added the following to my composer file:
"repositories": [{
"type": "vcs",
"url": "https://github.com/albertski/laravel-grid"
}],
When running composer show "albertski/laravel-grid" I get Package albertski/laravel-grid not found.
When I run composer require albertski/laravel-grid:3
.0-dev I get the following:
Could not find a matching version of package albertski/laravel-grid. Check
the package spelling, your version constraint and that the package is avail
able in a stability which matches your minimum-stability (dev).
Am I missing any steps? According to the docs that should be it. I am using Composer version 1.9.0.
This is my full composer.json file:
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.2",
"fideloper/proxy": "^4.0",
"laravel/browser-kit-testing": "^5.1",
"laravel/framework": "^6.0",
"laravel/tinker": "^1.0",
"laravel/ui": "^1.0"
},
"require-dev": {
"facade/ignition": "^1.4",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^3.0",
"phpunit/phpunit": "^8.0"
},
"repositories": [{
"type": "vcs",
"url": "https://github.com/albertski/laravel-grid"
}],
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
},
"files": ["tests/utilities/functions.php"]
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
],
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
]
}
}
Edit
Just to test it out I created a branch called 3.0_albert and updated the composer.json name field to "name": "albertski/laravel-grid",. (Not a fan of doing this because I eventually want to perform a pull request)
Then ran composer require albertski/laravel-grid:3.0_albert-dev but same issue.
I was able to figure it out. Instead of calling:
composer require albertski/laravel-grid:3.0.x-dev
You call:
composer require leantony/laravel-grid:3.0.x-dev
Basically by adding:
"repositories": [{
"type": "vcs",
"url": "https://github.com/albertski/laravel-grid"
}],
You are telling composer to check your repo first for the package instead of the default one.

Resources