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
  • 5,902
  • 3
  • 34
  • 60
Jeremy
  • 1,554
  • 1
  • 18
  • 35

1 Answers1

2

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

Yossi Nagar
  • 87
  • 2
  • 10