1
votes

Mates, im getting error sqlstate 42s22 columnactivity_post_commentsnot found 1054 unknown column in 'field list'

But this column name exists in my database.

I have checked my database and i have checked for spelling mistakes but im still getting this error

public function storecomments(Request $request, $id)
{
    // Create Comment
    $activity_post = new ActivityPost;
    $activity_post->activity_post_comments = $request->input('activity_post_comments');
    $activity_post->activity_post_id = $id;
    $activity_post->user_id = auth()->user()->id;
    $activity_post->save();

    return redirect()->back()->with('success', 'Comment Added');
}

Not sure why im getting this error so i cant save this values in my database

Model:

class ActivityPostComment extends Model
{
	use SoftDeletes;

    // Table Name
    protected $table = 'activity_post_comments';
    // Primary Key
    public $primaryKey = 'id';
    // Timestamps
    public $timestamps = true;

    /**
     * The attributes that should be mutated to dates.
     *
     * @var array
     */
    protected $dates = ['deleted_at'];

    public function post(){
        return $this->belongsTo('App\ActivityPost');
    }
}

Database Table

1
put your table structure too - Gaurav Gupta
@GauravGupta added - Rajveer Singh
Have you try with some default data instead of $request->input('activity_post_comments');? - DsRaj
you prolly haven't defined it in your model, but since you haven't posted it yet, im just guessin - Kevin
@RajveerSingh your calling wrong model your model class name is "ActivityPostComment" while you are using "ActivityPost" - Gaurav Gupta

1 Answers

1
votes

As per above code that you have posted . your calling wrong model your model class name is

ActivityPostComment

while you are using

ActivityPost