0

I created a new model "CategoryStatus" in my application.

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class CategoryStatus extends Model
{
    use SoftDeletes;

    protected $table = 'category_status';

    public $timestamps = true;

    protected $dates = ['deleted_at'];

    protected $fillable = ['status', 'category_id', 'user_id'];

    public function category()
    {
        return $this->belongsTo('App\Models\Category');
    }
}

I try to access my model like this:

CategoryStatus::where('id', $id)->first()

But every time I receive an error with the CORS policy (when I make an axios call with views). I installed the `spatie' extension which works from the beginning.

Access to XMLHttpRequest at 'http://myapp.test/api/bilan' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. 14:00:22.815

When I do my query with DB:: it works

I'm pretty sure it's not a CORS problem. Can you tell me why ?

Thank you

underscore_d
  • 6,309
  • 3
  • 38
  • 64
Jeremy
  • 1,756
  • 3
  • 21
  • 45

2 Answers2

2

When you using soft delete option you need to add use Illuminate\Database\Eloquent\SoftDeletes;

Yossi Nagar
  • 87
  • 2
  • 10
0

You need to add use Illuminate\Database\Eloquent\SoftDeletes;at the top of the model file and then add the deleted_at column to the $fillable array.

It's a little strange, but I don't know why this is happening.Even the Laravel document didn't mention it.