There is a table that consists of half foreign keys. table with foreign keys As in Laravel, through the DB facade, build a query so that full infa instead of keys is displayed. The sql query itself is simple, but I don’t know how to build it in laravel. Request example:

SELECT `vidacha knig`.`nomer zapisi`, `Chitatel`.`familia` FROM `Chitatel`,`vidacha knig` WHERE `Chitatel`.`Nomer chitatelya` = `vidacha knig`.`nomer chitatelya` 

How to do similar in laravel? Maybe there is a way to build a query in pure sql

  • Do you use models on the laravel side? - n.osennij
  • I have a problem with migrations to laravel. After migrations, my mysql starts to produce a bunch of errors. Tables are created, and then it is impossible to work with them, connections are not created both from the side of mysql and from the side of laravel. If you create tables manually, then the connections of the database as a whole work. I use models, but so far I need to deal with the connections. I have not fully understood the problem. As a solution to one of the problems - to update mysql, but with this there are difficulties, because there is little experience. - elVladosios
  • Try to take courses - youtube.com/… . There are Russian subtitles. You can skip the first lessons with working environment problems. As a local server under windows, try xampp, laragon or openserver - n.osennij

2 answers 2

You need join , here's an example of a query for Laravel:

 $query = DB::table('vidacha knig') ->join('Chitatel', 'vidacha knig.nomer chitatelya', '=', 'Chitatel.Nomer chitatelya') ->order_by('topic_time', 'desc')->get(); 

Further transfer $query to representation.

I really do not know whether to work with spaces (most likely not). If I were you, I would get rid of the spaces in the names of the fields and tables.

Documentation for working with Laravel databases.

    You can wrap all this in a model, i.e. A model for records, readers, librarians and books to make connections (in your case it belongsTo ). And then work through the ORM query designer. This is in many cases more convenient than writing queries.