Ad
PHP Error: Call To Undefined Method StdClass::save() In Psy Shell Code On Line 1
I'm new in Laravel, I'm using tinker to create a record:
$Profile=new \App\Profile();
=> App\Profile {#3038}
>>> $profile->title='Premier Titre'
PHP Warning: Creating default object from empty value in Psy Shell code on line 1
>>> $profile->title='Premier Titre';
=> "Premier Titre"
>>> $profile->description='Description';
=> "Description"
>>> $profile->user_id=1;
=> 1
>>> $profile->save()
PH
I have the following error:PHP Error: Call to undefined method stdClass::save() in Psy Shell code on line 1
Here my profile.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Profile extends Model
{
public function user()
{
return $this->belongsTo(User::class );
}
}
here is my migration code:
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('surname')->unique();
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
thanks in advance
Ad
Answer
The problem here is that you define variable with capital letter:
$Profile=new \App\Profile();
and later you use it with small letter
$profile->title='Premier Titre'
So probably under the hood new stdClass object is created and obviously it doesn't have save
method. You are also getting warning about this:
PHP Warning: Creating default object from empty value in Psy Shell code on line 1
which says new object is created
So make sure you change
$Profile=new \App\Profile();
into
$profile=new \App\Profile();
to make it working
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms
Ad