Category : eloquent

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (acl.report_saved, CONSTRAINT report_saved_user_id_foreign FOREIGN KEY (user_id) REFERENCES users (id)) (SQL: insert into report_saved (created_at, report_id, updated_at, user_id) values (2020-11-25 12:06:20, 10, 2020-11-25 12:06:20, 10)) I have two models: user and report and I’ve created a report_saved pivot table ..

Read more

{ "id": 1000, "name": "a:2:{s:2:"ar";s:8:"اخري";s:2:"en";s:5:"Other";}", "logo": "uploads/vehicleBrand/1577016358.png", "ordering": 1000, "status": 1, "created_by": null, "updated_by": null, "created_at": null, "updated_at": "2019-12-22 16:05:58", "deleted_at": null }, { "id": 1007, "name": "a:2:{s:2:"ar";s:12:"تويوتا";s:2:"en";s:6:"Toyota";}", "logo": "uploads/vehicleBrand/1577107221.png", "ordering": 1, "status": 1, "created_by": null, "updated_by": null, "created_at": "2019-12-23 17:20:21", "updated_at": "2019-12-23 17:20:21", "deleted_at": null }, { "id": 1008, "name": "a:2:{s:2:"ar";s:6:"كيا";s:2:"en";s:3:"KIA";}", "logo": "uploads/vehicleBrand/1577107281.jpg", "ordering": ..

Read more

I am trying ORM one to one relationship. I dont know why it cant recognize model class phone. code as follows. Phone.php <?php namespace AppModels; use IlluminateContractsAuthMustVerifyEmail; use IlluminateDatabaseEloquentFactoriesHasFactory; use IlluminateDatabaseEloquentRelationsHasOne; use IlluminateFoundationAuthUser as Authenticatable; use IlluminateNotificationsNotifiable; class User extends Authenticatable { use HasFactory, Notifiable; /** * The attributes that are mass assignable. * * ..

Read more

I’m starting a project using Slim and Eloquent, the connection with my database is working perfectly. My problem is that I can’t add an entry to my tests table. Here is my Model use PsrHttpMessageResponseInterface as Response; use AppDomainTestTest; use IlluminateHttpRequest; class NewTestAction extends TestAction { protected function action(): Response { $data = $this->request->getParsedBody(); $test ..

Read more

I’m building a webapp which have two databases: First: Database for user registrations, sign up etc. / in MySQL Second: Database for the stock market data / in PostgreSQL This is my env file: DB_CONNECTION=mysql DB_HOST=localhost DB_PORT=3306 DB_DATABASE=panel DB_USERNAME=root DB_PASSWORD= DB_CONNECTION_SECOND=pgsql DB_HOST_SECOND=localhost DB_PORT_SECOND=5432 DB_DATABASE_SECOND=assets_daily_info DB_USERNAME_SECOND=postgres DB_PASSWORD_SECOND=1234 And here is the database config php file: ‘mysql’ ..

Read more

I’m searching to load a relation inside a pivot table with "->with()". Table structure: Are 5 tables and Laravel Eloquent models user (id) team (id) role (id) team_user (id, team_id, user_id) team_user_role (id, team_user_id, role_id) class User extends Model { function teams(){ return $this->belongsToMany(Team::class) ->using(TeamUser::class); } } class Team extends Model { function users(){ return ..

Read more

I have a problem with some conflict in this query (whole query on bottom) It was working fine before I have added that part : ->join(‘ports’, ‘items.ports_id’, ‘ports.id’) ->join(‘cities’, ‘ports.cities_id’, ‘cities.id’) ->join(‘regions’, ‘cities.regions_id’, ‘regions.id’) ->join(‘countries’, ‘regions.countries_id’, ‘countries.id’) // works WHEN $place selected ->when($place, function($query) use ($place) { $query->where(‘ports.name’, $place) ->orWhere(‘cities.name’, $place) ->orWhere(‘regions.name’, $place) ->orWhere(‘countries.name’, $place); ..

Read more

I’m using laravel 8, trying to retrieve data from related models which returns empty arrays except for the parent model. I have 4 models Product (Parent) Product_categories Product_attributes Product_photos I’m fetching the data like this $product = Product::select(‘name’, ‘description’, ‘price’) ->with([‘categories’ => function($query){ $query->select([‘category_id’]); }, ‘attributes’ => function($query){ $query->select([‘attribute_key’, ‘attribute_value’]); }, ‘photos’ => function($query){ $query->select([‘photo_path’]); ..

Read more

I have a project which have multiple subdomains. for example I have a subdomain for Students which goes to a student controller and it looks like this: Route::domain(‘students.domain.test’)->group(function () { Route::get(‘/’, function () { return "done reaching the students page"; }); }); The second type of domains is "domain.test" and any subdomain which I’m checking ..

Read more