in Education by
When I have started with the project using Laravel 5.7 and PHP 7.3, $info->id returned correctly the last insert id. Now, I did some changes at the login file (all changes are here) and not at this files, but it doesn't work. The gf_id in the table is autoincrement, the function $info->id return null. I have tried to delete the row "public $incrementing = false;" and to set it to false but there aren't any changes. I have tried with other function like $info->_id or $this->id and also have changed $info->save with $info->create but nothing, always null. If I use getPrimaryKey return the error "Call to undefined method". In the database the row is created correctly. If I print the object $info with dd($info);, the result is this: GfTableModel {#233 #table: "gf_table" #primaryKey: "gf_id" +timestamps: false +incrementing: false #connection: "mysql" #keyType: "int" #with: [] #withCount: [] #perPage: 15 +exists: true +wasRecentlyCreated: true #attributes: array:5 [ "gf_user" => 5 "gf_new" => 1 "gf_data" => "2019-03-22 14:08:28" "gf_object" => "" "gf_text" => "" ] #original: array:5 [ "gf_user" => 5 "gf_new" => 1 "gf_data" => "2019-03-22 14:08:28" "gf_object" => "" "gf_text" => "" ] #changes: [] #casts: [] #dates: [] #dateFormat: null #appends: [] #dispatchesEvents: [] #observables: [] #relations: [] #touches: [] #hidden: [] #visible: [] #fillable: [] #guarded: array:1 [ 0 => "*" ] } This is my GfTableModel.php: <?php namespace App; use Illuminate\Database\Eloquent\Model; class GfTableModel extends Model { protected $table = 'gf_table'; protected $primaryKey = 'gf_id'; public $timestamps = false; public $incrementing = true; public function insertNewRow(){ $info = new GfTableModel(); $info->gf_user = auth()->id(); $info->gf_data = date("Y-m-d H:i:s"); $info->gf_new = 1; $info->gf_object = ""; $info->gf_text = ""; $info->save(); return $info->id; } } Where am I doing wrong? Could it be a problem given by the command php artisan config: cache? Thank you JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I ran into something similar. As of Laravel 5.7, 5.8 you can do this: return $info->getKey(); This works regardless of the name of the primary key.

Related questions

0 votes
    When I have started with the project using Laravel 5.7 and PHP 7.3, $info->id returned correctly the last insert id. Now, I did ... :1 [ 0 => "*" ] } This is my GfTableModel.php:...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    In Laravel, there is a function return back();, which returns the user to the previous page. Is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    I'm trying to insert data to the database and at the same time uploading an image to the path. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I have a question. If created_at in my database is datetime and I want to make a query like this ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    I have a question. If created_at in my database is datetime and I want to make a query like this ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I have a question. If created_at in my database is datetime and I want to make a query like this ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    I have a table structure like this : subscribers with attributes: id, status I want to have a way ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I want to load Google fonts in the head-section of my page using a php-function. My -area looks like this: ... ... Now ... I do this, there will be a "1" displayed (because of the...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I want to load Google fonts in the head-section of my page using a php-function. My -area looks like this: ... ... Now ... I do this, there will be a "1" displayed (because of the...
asked May 30, 2022 in Education by JackTerrance
0 votes
    I want to load Google fonts in the head-section of my page using a php-function. My -area looks like this: ... ... Now ... I do this, there will be a "1" displayed (because of the...
asked May 26, 2022 in Education by JackTerrance
0 votes
    I want to load Google fonts in the head-section of my page using a php-function. My -area looks like this: ... ... Now ... I do this, there will be a "1" displayed (because of the...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I have 2 buckets prod and dev. Inside .env I have S3_PROD and S3_DEV. I want my system to point ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    I have 2 buckets prod and dev. Inside .env I have S3_PROD and S3_DEV. I want my system to point ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 27, 2022 in Education by JackTerrance
0 votes
    I am aware that I can use array_unique(array_merge($a,$b)); to merge two arrays and then remove ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 14, 2022 in Education by JackTerrance
0 votes
    Recently I asked a question regarding preg_match_all with php, and i got the perfect solution as expected ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 11, 2022 in Education by JackTerrance
...