skip to Main Content

enter image description here

I gave my table name to the models file I created and it gave syntax error

Syntax error: unexpected token ‘$table’

2

Answers


  1. the $table variable is a class property, and class properties needs to be defined with their visibility as a prefix ( public, protected or private ).

    In this particular case, the $table property is already define on the Model, so we know it’s visibility, it’s protected.

    class YourModel extends Model {
      protected $table = "your table";
    }
    
    Login or Signup to reply.
  2. We have to define the access modifier for that class property.

    For table use :- protected $table = "users"

    You may define the primary key field name for your table so model will known for that.

    protected $primaryKey = "code";
    

    If you model has non-integer data type primary key field then you have to define these below in model
    Example : In you model has code is primary key so according to it is string datatype so you have define that as given below example.

    protected $keyType = 'string';
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search